It is currently May 8th, 2024, 1:48 pm

AutoIT questions

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16203
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

AutoIT questions

Post by balala »

Recently I've installed AutoIt and started to work. But now I have a few questions, if someone can help:
1. There is any possibility to get the value of a variable into the AutoIt script? I can read the ini or inc file (using the IniRead function), but I'd need a way to get even a new value of the variable, set with the !SetVariable option. Can it be done?
2. First I thought it'll be possible to use the au3 script in the same way as a lua script. Obviously it's not possible, because as the Help sais, a Script measure
measures information returned using the Lua scripting language
So, there is any possibility to use a such au3 script, or it must be compiled and use the exe?
3. One more question, if only the exe can be used: I wrote the following very simple AutoIt script:

Code: Select all

#include <WinAPIFiles.au3>
#include <SendMessage.au3>
#include <MsgBoxConstants.au3>

SendBang('!SetVariable Var "' & ReadTheFile() & '"')
Exit (0)


Func SendBang($szBang)
	local Const $hWnd = WinGetHandle("[CLASS:RainmeterMeterWindow]")
	if $hWnd <> 0 then
		local Const $iSize = StringLen($szBang) + 1
		local Const $pMem = DllStructCreate("wchar[" & $iSize & "]")
		DllStructSetData($pMem, 1, $szBang)
		local Const $pCds = DllStructCreate("dword;dword;ptr")
		DllStructSetData($pCds, 1, 1)
		DllStructSetData($pCds, 2, ($iSize * 2))
		DllStructSetData($pCds, 3, DllStructGetPtr($pMem))
		local Const $WM_COPYDATA = 0x004A
		_SendMessage($hWnd, $WM_COPYDATA, 0, DllStructGetPtr($pCds))
	endif
 EndFunc

Func ReadTheFile()
    Local Const $sFilePath = "Variables.inc"
    Local $hFileOpen = FileOpen($sFilePath, $FO_READ)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
        Return False
    EndIf
	Local $sFileRead = IniRead($sFilePath, "Variables", "MyVar", "")
    FileClose($hFileOpen)

    Return ($sFileRead)
EndFunc
This script will read the value of the MyVar variable, set into the [Variables] section of the Variables.inc file, and will send it to the skin, through the Var variable (yes, I know that for a such task an AutoIt script is not needed, but it'll be part of a larger project, which I think can't be done without AutoIt). If I compile the script and use it as an exe, I have to run it on each update cycle (once per second):

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
OnUpdateAction=["#@#ReadMyVar.exe"]

[MeterResult]
Meter=String
X=0
Y=0
Padding=15,5,15,5
FontSize=14
FontColor=255,255,255
SolidColor=0,0,0,120
AntiAlias=1
Text=#Var#
DynamicVariables=1
But this procedure has the disadvantage that each time the exe is run, the mouse pointer is changing for a moment to Working in Background, then immediately back, indicating a work in background. Could be this avoided? I tried to use the RunCommand plugin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
OnUpdateAction=[!CommandMeasure MeasureRun "Run"]

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=#@#ReadMyVar.exe
State=Hide

[MeterResult]
Meter=String
X=0
Y=0
Padding=15,5,15,5
FontSize=14
FontColor=255,255,255
SolidColor=0,0,0,120
AntiAlias=1
Text=#Var#
DynamicVariables=1
but it had the same result.
So could be used the ReadMyVar.exe in way to avoid this continuous pointer changing?
I attached the skin.

Thanks in advance.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AutoIT questions

Post by jsmorley »

There is really no way for an AutoIt script / exe to read anything from the current memory of Rainmeter. The only interaction with Rainmeter is to send command line parameters to the AutoIt when you execute it. Nothing "dynamic" in Rainmeter is going to be available to you.

There is no "re-entrant" capability that is easy with AutoIt. I have never really found a way to send something to an AutoIt program that is already running, only executing it entirely again with a new command line. Having an AutoIt program "always running" and you just send it "new" information isn't really possible with a .exe approach, you would need some kind of .dll approach that is a "child" of Rainmeter (exactly what a "plugin" is).

Really the only thing AutoIt can get directly from Rainmeter is some high-level information about where the Rainmeter.exe is, what is the path to the "skins" and "settings" folders, and what if any text editor is set for it.

https://docs.rainmeter.net/developers/

When you execute any external .exe file, Windows will display the "busy" cursor for a second while the external application loads. There is no way I have ever found to avoid this.

AutoIt is not a good replacement for Plugins or Lua scripts in an interactive way. It's better for some one-time execution like RainRGB that is manually run by the user with a mouse click.
User avatar
balala
Rainmeter Sage
Posts: 16203
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: AutoIT questions

Post by balala »

Thanks jsmorley for the quick reply. Bad enough for me that running the exe each update cycle is not a good idea, but it seems that I'll have to find another way to handle this.
There is any way to "translate" the AutoIt code to lua? Or could be created a plugin from it?
Thanks again.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AutoIT questions

Post by jsmorley »

balala wrote:Thanks jsmorley for the quick reply. Bad enough for me that running the exe each update cycle is not a good idea, but it seems that I'll have to find another way to handle this.
There is any way to "translate" the AutoIt code to lua? Or could be created a plugin from it?
Thanks again.
No, you would have to just understand what the AutoIt is doing, and replicate that functionality in either a plugin or Lua. There is no way you can "translate" between them.
User avatar
balala
Rainmeter Sage
Posts: 16203
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: AutoIT questions

Post by balala »

And a plugin could be created based on the AutoIt code?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AutoIT questions

Post by jsmorley »

balala wrote:And a plugin could be created based on the AutoIt code?
No, you would have to figure out what the AutoIt is trying to do, and create a plugin in C++ or C# that does what you want. While it might be possible for someone to figure out how to add AutoIt to the Plugin SDK for Rainmeter, where you would compile the AutoIt program as a .dll and create the "hooks" to the Rainmeter API, I wouldn't even know where to start, and it would be a very complex undertaking with no certainty of success...
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AutoIT questions

Post by jsmorley »

AutoIt is based on a lot of Windows API calls in C, so it might be possible to search the Microsoft Visual Studio documentation to find the underlying routines for C++ that will do what you want in a plugin.
User avatar
balala
Rainmeter Sage
Posts: 16203
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: AutoIT questions

Post by balala »

Ok, thanks jsmorley, I understood.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AutoIT questions

Post by jsmorley »

A plugin is almost always going to be the best approach if you are trying to do "external things" in Windows that are beyond the capabilities of Lua, which is "platform agnostic" and really doesn't even know about Windows. There is pretty much no limit to what you can do in C++ or C#, and the Plugin SDK will connect your plugin to the Rainmeter skin that executes it.

AutoIt is good if you want to have Rainmeter execute some program and send command line parameters to it, then have that program do whatever, and send the results back to the Rainmeter skin as "bangs". It's a "handoff" back and forth, and really, really isn't good for something you need to execute on every skin update.

I don't have a strong preference for C++ vs. C#, I find C++ to be a bit more powerful, but C# to be a bit easier for someone new at it to wrap their head around.

Do be aware though that if you decide to go this route and need help, you are more likely to get it if you use C++, as the developers here really look down their noses at C# and have very limited experience with it...

There are also some minor issues around which version of the C# .NET runtime libraries you code to, and ensuring that if you use a recent version of .NET, that everyone that uses your skin has the correct version of the runtimes. With C++, you are going to just be leveraging the VC++ runtime libraries that Rainmeter already uses. This is going to be less of an issue now that we threw XP under the bus...
User avatar
balala
Rainmeter Sage
Posts: 16203
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: AutoIT questions

Post by balala »

Thanks jsmorley. I'll try to do something with it.