Why bother?
- Rainmeter is a simple way to put up attractive UI on the desktop, and can make a quick and effective way to provide interfacing with AHK's capabilities
- Allow keyboard control of desktop widgets (start a timer widget, turn widgets transparent)
- Use AHK's better integration tools and APIs to augment Rainmeter skins (e.g. getting play count of the current track from my music player)
- Use Rainmeter to show status of something that's easier to track with AHK (is a certain background process running?)
- Tying together tools == synergy!
Here are the two ways I know of to send Rainmeter commands (the unfortunately-named bangs) from AHK:
First is to call its .exe directly with parameters. This works well, is simple, and depends on knowing where the .exe lives:
Code: Select all
RainmeterPath := "C:\Program Files\Rainmeter\rainmeter.exe"
SendRainmeterCommand(Command) {
global RainmeterPath
Run, %RainmeterPath% %Command%
}
Code: Select all
SendRainmeterCommand(command) {
Send_WM_COPYDATA(command, "DummyRainWClass")
}
Send_WM_COPYDATA(ByRef StringToSend, ByRef TargetWindowClass) ; ByRef saves a little memory in this case.
; This function sends the specified string to the specified window and returns the reply.
; Cribbed from https://www.autohotkey.com/docs/commands/OnMessage.htm
{
VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0) ; Set up the structure's memory area.
; First set the structure's cbData member to the size of the string, including its zero terminator:
SizeInBytes := (StrLen(StringToSend) + 1) * (A_IsUnicode ? 2 : 1)
NumPut(1, CopyDataStruct) ; Per example at https://docs.rainmeter.net/developers/
NumPut(SizeInBytes, CopyDataStruct, A_PtrSize) ; OS requires that this be done.
NumPut(&StringToSend, CopyDataStruct, 2*A_PtrSize) ; Set lpData to point to the string itself.
SendMessage, 0x4a, 0, &CopyDataStruct,, ahk_class %TargetWindowClass% ; 0x4a is WM_COPYDATA. Must use Send not Post.
return ErrorLevel ; Return SendMessage's reply back to our caller.
}
Going the other way, using window messaging again, requires a couple things set up. In the Rainmeter skin, you need to have a measure dedicated to sending out window messages to AHK, like so:
Code: Select all
[MeasureAhkWindowMessaging]
Measure=Plugin
Plugin=WindowMessagePlugin
WindowClass=AutoHotkey
Code: Select all
LeftMouseUpAction=[!CommandMeasure MeasureAhkWindowMessaging "SendMessage 16687 2 0"]
Code: Select all
OnMessage(16687, "RainmeterWindowMessage")
RainmeterWindowMessage(wParam, lParam) {
If (wParam = 2) {
CheckPlayCount()
}
}
Anyone else here using these great tools together?
(Note: Sorry for not linking, apparently I'm new enough to the forums that links are disabled for me.)