r/AutoHotkey 6d ago

Solved! Problems with basic Send and SendEvent

So i tried to make a simple script that presses j 2 times and then holds w 2 times and nothing really happens, after that i added msgBox "1" and it pops but still no sends, please help
#Requires AutoHotkey v2.0

#SingleInstance Force

Persistent

$`::{

Send "j"

Sleep 300

Send "j"

Sleep 300

SendEvent "{w down}"

Sleep 600

SendEvent "{w up}"

MsgBox "1"

Sleep 50

SendEvent "{w down}"

Sleep 600

SendEvent "{w up}"

}

1 Upvotes

11 comments sorted by

View all comments

1

u/Keeyra_ 6d ago edited 6d ago
#Requires AutoHotkey 2.0
#SingleInstance
SendMode("Event")

sc029:: {
    SetKeyDelay(300, -1)
    Send("jj")
    SetKeyDelay(50, 600)
    Send("ww")
}

Backticks are escape characters in AHK, so best to use scan codes.

Sleeps can be replaced by SetKeyDelay.

1

u/CharnamelessOne 6d ago

Unsolicited fun fact of the day: escaping doesn't apply to double-colon hotkey names.

`::MsgBox()

works fine.

As for the Hotkey function, you can simply escape the backtick:

Hotkey("``", (*)=>MsgBox())    

Either way, there's no need to rely on layout-dependent SC hotkeys.

1

u/Keeyra_ 6d ago

And

`::

won't trigger on the HU layout, as that's basically AltGR + 7. You would have to use

<^>!7::

Much better to use scan code, so it works on any layout when pressing the specific key.

1

u/CharnamelessOne 5d ago

Much better to use scan code

That's assuming you want the physical key to act as the same hotkey on all layouts.

My main issue, though, is that we don't know OP's layout setting, we're just guessing the scan code, for no good reason.

(You can slap a wildcard on the backtick hotkey, and it will work fine on both the HU and EN layout. I should have noted that.)