Ctrl, Alt, Win and Shift are commonly known as modifier keys. Usually they are combined with other keys such as A, =, F5 etc. autoit follows this key binding limitation. autohotkey doesn't.
How come AutoHotkey is able to use RCtrl as individual hotkey while AutoIt can't? I wonder what tricks AutoHotkey used to accomplish that. AutoHotkey is derived from AutoIt v2, so isn't it weird for AutoIt v3 to not be able to do that?
This is valid in AutoHotkey:RAlt::Run Notepad
, but the following code won't work with AutoIt v3 (checked with Au3Check):
HotKeySet("{RAlt}","RunNotepad")
Func RunNotepad()
Run('notepad.exe')
EndFunc
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.