more succint, built-in way to dynamically remap keys via the Hotkey() function
Posted: 23 Aug 2023, 23:39
Currently the Hotkey() function can be used to disable a remapping. Example from doc:
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):
This isn't a lot of code to write, but then again, it's not a lot of code to write this either
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 ...)
Code: Select all
Hotkey("*a", "Off")
Hotkey("*a up", "Off")
Code: Select all
Hotkey("*b", (hk) => (SetKeyDelay(-1), Send("{Blind}{a DownR}")) )
Hotkey("*b up", (hk) => (SetKeyDelay(-1), Send("{Blind}{a Up}")) )
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}"
}
(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 ...)