AutoHotkey usage
Using .ahk files in a module
The following guide will show you how you can use AHK to run 2 toggling bangs by pressing a hotkey for your module. Of course, this isn't what AHK is limited to do, as demonstrated by the YourFlyouts module.
Getting started
Create file ./@Resources/Actions/Source code/#SKINNAME#.ahk
#SingleInstance Force
#NoTrayIcon
SetTitleMatchMode, 2
DetectHiddenWindows, On
IniRead, OutputVar, Hotkeys.ini, Variables, Key
IniRead, RainmeterPath, Hotkeys.ini, Variables, RMPATH
Hotkey,%OutputVar%,Button
Return
Button:
Run "%RainmeterPath% "!UpdateMeasure "mToggle" "#SKINNAME#\Main" "
Return
And create file ./@Resources/Actions/Source code/Close.ahk
#NoTrayIcon
IniRead, OutputVar, CloseInstance.ini, Variables, Module
CloseScript(Name)
{
DetectHiddenWindows On
SetTitleMatchMode RegEx
IfWinExist, i)%Name%.* ahk_class AutoHotkey
{
WinClose
WinWaitClose, i)%Name%.* ahk_class AutoHotkey, , 2
If ErrorLevel
return "Unable to close " . Name
else
return "Closed " . Name
}
else
return Name . " not found"
}
CloseScript("#SKINNAME#.ahk")
ExitApp
And finally, create file ./@Resources/Actions/Hotkeys.ini
[Variables]
Key=
RMPATH=
KeyInString=
🎉Congratulations! All necessary files have been created. Lets move on to the code part...
Assigning default values
As you can see, in Hotkeys.ini
the values are blank. We'll have to assign a default value first.
You can either put these values in the file, to make the default hotkey
LWin W
Key=#W KeyInString=LWin W
Or you can visit your settings page (if you made one) and change the hotkey.
Open the
@Start
skin from the Rainmeter manage panel.
Integration to your module
As you've read about themToggle measure, lets use that to toggle our module.
Paste the 2 blocks into your main skin file.
Add the following contents to the
[Rainmeter]
section:[Rainmeter] DefaultAlwaysOnTop=1 OnRefreshAction=...["#@#Actions\AHKv1.exe" "#@#Actions\Source Code\#SKINNAME#.ahk"] OnUnfocusAction=[!UpdateMeasure mToggleSet] OncloseAction=["#@#Actions\AHKv1.exe" "#@#Actions\Source Code\Close.ahk"]
This allows the module to:
Always stay on top of other windows
Launch the ahk process when the module is activated
Dismiss on unfocus
Close all ahk process when the module exits
Create 2 NUOL measures:
ACTIONLOAD
&ACTIONUNLOAD
, and have theirOnUpdateAction
be whatever you want
Last updated
Was this helpful?