There's a recent article (<!-- m -->http://stevelosh.com...rn-space-cadet/<!-- m -->) that details a hotkey technique of overriding the default behavior of a modifier key (ctrl, alt, shift...) when it is pressed alone. So if you hit CTRL+C you get the default behavior of exiting a terminal program, or copying text, but if you hit CTRL alone it can trigger a different keypress or launch a script.
The author maps a lone CTRL to ESC (for vim), and maps left and right shift keys to open and closing parentheses.
Is this possible in AHK? How do you remap something with those strict conditions?
Override key behavior when other keys aren't pressed?
Started by
Guest
, Oct 04 2012 02:26 PM
5 replies to this topic
#1
-
Posted 04 October 2012 - 02:26 PM
This is done naturally by AHK, different modifiers can cause different events despite remapping the modifiers. If you want a combination to be changed you must remap that combination. So your request is extremely simple, if you'd tested it yourself you would have seen it:
And Ctrl+c will function as it normally does...
Ctrl:: Send {esc} Return
And Ctrl+c will function as it normally does...
#2
-
Posted 04 October 2012 - 02:46 PM
This is done naturally by AHK, different modifiers can cause different events despite remapping the modifiers. If you want a combination to be changed you must remap that combination. So your request is extremely simple, if you'd tested it yourself you would have seen it:
Ctrl:: Send {esc} Return
And Ctrl+c will function as it normally does...
Hey this is great!
Is there a way to do the shift-parens thing though? When i hold a shift key, it repeatedly sends the paren, effectively disabling the shift key as a modifier:
LShift:: send {(} Return
#3
-
Posted 04 October 2012 - 04:39 PM
I'm afraid it's not so simple. Here is a script which needs thorough testing.
$LShift:: Send {LShift down} KeyWait LShift Send {LShift up} If A_PriorKey = LShift Send {(} return $RShift:: Send {RShift down} KeyWait RShift Send {RShift up} If A_PriorKey = RShift Send {)} return
#4
-
Posted 04 October 2012 - 06:06 PM
I forgot to say that my script works only with AHK_L
#5
-
Posted 04 October 2012 - 06:30 PM
Works fine for me in AHK Basic with just a few changes:
$LShift:: $RShift:: Key := SubStr(A_ThisHotkey,2) Send, {%Key% Down} KeyWait, %Key% Send, {%Key% Up} If ( A_PriorHotkey == A_ThisHotkey ) SendRaw, % InStr(Key,"L") ? "(" : ")" Return
#6
-
Posted 04 October 2012 - 06:33 PM
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.