简体   繁体   中英

How to disable keyboard remap if a modifier key is down?

I'm using a different keyboard layout, using AHK's qwerty to colemak script. It remaps letters to different letters. How can I disable it when either the ctrl, alt, or windows key is down. This way hotkeys like ctrl+s to save should still work!

Edit: I got the script from here http://colemak.com/wiki/index.php?title=Download

It just looks like this

r::p
t::g
y::j
u::l

Use Suspend to disable hotkeys. Use ~ tells AHK not to block the native event. Then use Suspend again to re-enable the hotkeys.

~Ctrl::Suspend, On
~Ctrl Up::Suspend, Off

~Alt::Suspend, On
~Alt Up::Suspend, Off

~LWin::Suspend, On
~LWin Up::Suspend, Off

Although I wrote in the comment above that I think this conditional disabling is not required, here is some code. I used the letter f and tested in in Notepad. Pressing f returns Hello Pressing ^f should give hELLO, but since the #IF is not true the notepad find opens up since the system sends a regular Ctrl+f. Same for !f, this opens up the File menu. WARNING you MUST have autoHotKey_L installed for #IF to work!

#If (NOT ((GetKeyState("Control", "P")) OR (GetKeyState("Alt", "P"))))
    f::Send, Hello ; Should execute as long as Ctrl or Alt are not pressed.
    *a::Send, QQQQ ; The * ignores all modyfiers, not executed when Alt or Ctrl is pressed.
    ^f::Send, hELLO ; should never execute due to #IF = False
    !f::Send, olleh ; should never execute due to #IF = False
#IF


including the code of the script or providing a link to the script (i was searching it myself but could not find it) would help.

If remaping in the script was done correctly the combination Ctrl + S should still work, although the physical position of the key has changed. As i have seen in the layout
http://colemak.com/wiki/images/8/80/Colemak_layout_2.png
s isn't that far away from the original s so you could try just remembering it.



The usual solution for disabling the hotkeys is:

    Suspend, On

http://www.autohotkey.com/docs/commands/Suspend.htm

Since i didn't see the script i don't know if it will work.

Same as above. Not sure about the script. An idea might be to use the autoHotKey_L #if function and place the re-assigned keys inside the #IF. The #IF should then be created around the modifier keys not being 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