简体   繁体   中英

Store key modifier as variable

Is there way to use variable for key modifier, for example:

var = +
%var%c:: do something  ; Equal to Shift-C

... Well, StackOverflow trying to force me to write something more about the task. But I'm really don't know what to add to what have been already said. Also I've already read AHK forums, but can't find answer there.

Dynamic hotkeys are defined using the Hotkey command.

From the AHK website on hotkeys: https://autohotkey.com/docs/Hotkeys.htm

By means of the Hotkey command, hotkeys can be created dynamically while the script is running. The Hotkey command can also modify, disable, or enable the script's existing hotkeys individually.

This faq page on dynamic variables provides something close to what you are asking for: https://autohotkey.com/board/topic/97097-faq-variables-dynamic-variables-literal-strings-and-stuff-like-that/

keys = abcdefghijklmnopqrstuvwxyz
StringSplit, keys, keys

Loop, %keys0%
    Hotkey, % keys%A_Index%, keydown

return
keydown:
ToolTip, %A_ThisHotkey% was pressed

I've verified that the following works as expected:

var = +c
Hotkey, %var%, keydown
return
keydown:
ToolTip, %A_ThisHotkey% was pressed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM