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

Tag: autohotkey Author: jiangqian311 Date: 2012-12-30

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
Wait a moment, if you remap this way, then the modifiers are not defined anyway, so pressing s gives an r, but pressing +s still gives S, pressing ^s still gives ^s and pressing !s still gives !s. I don't see a reason to "disable" conditionally. Help me understand! B.t.w. the wiki looks to contain compiled binaries, not the source scripts.
It's true that ^s still works, the s is just in a different location. But this is a huge problem. Applications usually choose hotkeys based on their position on a qwerty keyboard. ^e for example is on the other side of the keyboard for me, and makes for really inefficient hotkeys.

Best Answer

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

Other Answer1

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

comments:

William, This solution is much easier and I have thought about offering this as well. The down-side is that everything in the script is suspended. In that case, I would place the hotkeys that you want to suspend in one script and everything else in a second script. and just run two scripts in parallel (with different icons to visually differentiate them)

Other Answer2


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.

Other Answer3

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.

comments:

Sounds like a good solution. But, how do I write if no modifiers are down, except for shift?
This is not clear (or so obvious that I am overlooking it), but what do you want to do now? Do you want to ADD a new #IF section just for Shift? or ADD shift to the existing #IF NOT(xxx)? I still think that you are making this way to complicated. just define a::something, +a::something else, !a::something else again, #a::Something else, ^a::again something else, etc.