AutoHotkey usage

Using .ahk files in a module

Replace all #SKINNAME# instances you see on this page with your module name

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.

  1. 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.

  2. Open the @Start skin from the Rainmeter manage panel.

Integration to your module

This method works, but can be more efficient by the use of a lua script.

  1. Paste the 2 blocks into your main skin file.

  2. 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:

    1. Always stay on top of other windows

    2. Launch the ahk process when the module is activated

    3. Dismiss on unfocus

    4. Close all ahk process when the module exits

Last updated