how to Send A_ThisHotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
felixcatto
Posts: 6
Joined: 15 Aug 2021, 05:25

how to Send A_ThisHotkey

17 Sep 2021, 11:43

Hi, guys,
I have a script like this

Code: Select all

*a::
*s::
*d::
  ; some code
  ReplacedStr := StrReplace(A_ThisHotkey, "*", "")
  Send, ReplacedStr ; Doesnt' work
  Click, Down Right
  KeyWait, ReplacedStr  ; Doesnt' work
  Click, Up Right
  Return
But this doesn't work. Ofc i can replace A_ThisHotkey to "a", "s", "d" directly and copy this commad 3 times, but that's looks clumsy. Is there a way to send a same hotkey, triggered it?
User avatar
boiler
Posts: 17086
Joined: 21 Dec 2014, 02:44

Re: how to Send A_ThisHotkey

17 Sep 2021, 12:41

You need to put a $ in front of each of your hotkey definitions so the hotkey subroutine doesn’t trigger itself (in the case where you invoke the hotkey without modifiers), and then you need to strip that off as well. Your Send command is sending the actual name of the variable rather than the contents of the variable. Either force an expression by preceding the variable with % and a space or wrap the variable in percent signs.

You have the same issue with the KeyWait statement. You need to either force an expression or wrap the variable in percent signs to have it use the contents of the variable.

Code: Select all

$*a::
$*s::
$*d::
  ; some code
  ReplacedStr := StrReplace(A_ThisHotkey, "$*")
  Send, % ReplacedStr
  Click, Down Right
  KeyWait, % ReplacedStr
  Click, Up Right
  Return
felixcatto
Posts: 6
Joined: 15 Aug 2021, 05:25

Re: how to Send A_ThisHotkey

17 Sep 2021, 13:53

Seems i don't need a $ prefix because in documentation states that "It also has no effect for hotkeys which already require the keyboard hook, including any keyboard hotkeys with the tilde (~) or wildcard (*) modifiers"
But big thanks for expression syntax, now it works like i wanted <3

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RussF and 142 guests