1
votes

Ctrl, Alt, Win and Shift are commonly known as modifier keys. Usually they are combined with other keys such as A, =, F5 etc. follows this key binding limitation. 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
1
I have to make it clear that I'm not saying using modifier keys alone as a hotkey is a necessary feature or a good way to define hotkeys. I'm just curious about the low level implementation differences between AHK basic and AutoIt.Joshz

1 Answers

3
votes

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.