As a first note, your AutoIt code will run and then immediately exit. You need to add a loop in there to keep the program running.
I can't speak for the AHK implementation, but from testing with the windows api that AutoIt is almost certainly using (RegisterHotkey), I can't get just the VK_RMENU
key on its own. So this is a windows limitation rather than an AutoIt one.
As to alternative implementations, and how you could go about doing this from AutoIt, _IsPressed
is the easiest option. Normally you'd have _IsPressed
in a loop, but if you want it to behave a bit more like HotkeySet
then you could do something like:
#include <Misc.au3>
AdlibRegister(_TestRalt, 20)
While 1
Sleep(10)
WEnd
Func _RunNotepad()
ConsoleWrite("Just pretend I ran notepad" & @LF)
EndFunc ;==>_RunNotepad
Func _TestRalt()
Local Static $hUser32 = DllOpen("user32.dll")
Local Static $fPressed = False
If _IsPressed("A5", $hUser32) Then
$fPressed = True
ElseIf $fPressed Then
_RunNotepad()
$fPressed = False
EndIf
EndFunc ;==>_TestRalt
I suspect if AHK can do this out of the box, then they are doing something more complex like keyboard hooking.