more succint, built-in way to dynamically remap keys via the Hotkey() function

Propose new features and changes
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

more succint, built-in way to dynamically remap keys via the Hotkey() function

23 Aug 2023, 23:39

Currently the Hotkey() function can be used to disable a remapping. Example from doc:

Code: Select all

Hotkey("*a", "Off")
Hotkey("*a up", "Off")
But in order to dynamically create a remapping, it's necessary to write (I'm assuming this is how it's done, correct me if i'm wrong):

Code: Select all

Hotkey("*b", (hk) => (SetKeyDelay(-1),  Send("{Blind}{a DownR}")) )
Hotkey("*b up", (hk) => (SetKeyDelay(-1),  Send("{Blind}{a Up}")) )
This isn't a lot of code to write, but then again, it's not a lot of code to write this either

Code: Select all

*b::
{
    SetKeyDelay -1
    Send "{Blind}{a DownR}"  ; DownR is like Down except that other Send functions in the script won't assume "b" should stay down during their Send.
}

*b up::
{
    SetKeyDelay -1
    Send "{Blind}{a Up}"
}
Yet we have a syntactic sugar to write this succintly (i.e. b::a). I wonder if there's any special reason Hotkey() couldn't be given something similar.

(But perhaps there's no natural way to do this. The 2nd parameter of Hotkey function can take a hotkey name, but that doesn't create a remapping. Perhaps an option for remapping can be added in the 3rd paramter (e.g. Hotkey("a","b","R") establishes a remapping of a to b), but it doesn't seem very satisfactory either ...)
lexikos
Posts: 9637
Joined: 30 Sep 2013, 04:07
Contact:

Re: more succint, built-in way to dynamically remap keys via the Hotkey() function

24 Aug 2023, 06:51

You have the ability to define functions and call them to reduce code repetition. Use it.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 25 guests