4

There are two keys adjacent to the spacebar on standard Korean keyboards (one on each side) which I would like to remap to be Control or Alt modifiers - so I can alternate using a stronger finger than my pinky (I'm an emacs user).

I'm guessing the problem is that they do not seem to generate a KeyUp event, and they don't repeat like other keys. I've got a hacky solution that is terrible involving a loop using autohotkey. Also did something similar with another non-free program, KeyManager. I'm hoping for some more advanced trickery or workarounds (AutoHotkey, drivers or otherwise).

;Scan Code for Hanja Key
sc1F1::
Loop 10000
{
SetKeyDelay,-1
Send {Blind}{LCtrl DownTemp}
}
SetKeyDelay,-1
Send {Blind}{LCtrl Up}
Return

Keyboard Hook Output of Pressing (and holding) Hanja:

You can see there is no repeat and no up event.

VK  SC  Type    Up/Dn   Elapsed Key     Window
74  03F     u   0.08    F5              
19  1F1     d   0.66    Hanja           
74  03F     d   9.58    F5       

Updates:

Tried:

sc1F1 & t::Send {Blind}{LCtrl DownTemp}{t}{LCtrl Up}

Results:

After pressing Hanja+t, the hotkey fires, but then subsequent presses of ONLY t alone perform the same action. LCtrl Up doesn't appear to occur.

Abe's SetTimer based reset is nice though! feels like a more elegant version of my original code. However, the catch is the delay - I have to pace my input speed to match the delay.

Other tested solutions:

GetKeyState("vk19", "p") always reports PRESSED after script loads and one initial press. It never breaks this state - even long after i have released the key.

KeyWait also doesn't work as intended.

sc1F1 up::traytip,, test also does not produce a traytip after any number of press/releases.

assem
  • 2,077
  • 1
  • 19
  • 24
  • Always use AutoHotkey from http://ahkscript.org/ (current version, new official website)! AutoHotkey from autohotkey.com is outdated and you may have some problems running scripts with it! Also if you have any problem of getting the name for special keys that are not listed in AutoHotkey documentation check this answer: http://stackoverflow.com/questions/24921492/macro-keys-not-detected-autohotkey/24927828#24927828 – vasili111 Aug 05 '14 at 06:38

3 Answers3

1

Assem,

I have not yet finished this thought, but would this be an alternative approach? It will show you which keys are pressed until (in this case an enter is pressed), but you can maybe create your own "finish" condition and then "combine" the key presses to create your Alt or Ctrl combinations.

sc038:: ; Start when (in this case) the left Alt is pressed, {LAlt} is NOT listed in the input list....
input:=""
   Loop
   {
        Input, in, L1, {Enter}{LControl}{RControl}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}
        EL=%ErrorLevel%
        ToolTip, %EL% and %in% and %A_ThisHotkey%
        if EL = EndKey:Enter
        {
            ToolTip
            Sleep, 5000
            Break
        }
   }
Return
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
  • thanks for the snippet; but, not quite the solution i was hoping for. `Input` doesn't seem to support modifier keys. so if I want to support sc### (start sequence to be remapped to Ctrl) then Alt+Something or Shift+Something, i'm guessing this loop will become a lot more complex? – assem Aug 13 '12 at 14:16
  • You are right that input doesn't combine the various modifiers, but (depending on the added special keys as arguments) input will process each pressed key individually. I was thinking that if your key combinations (which will be processed one by one with input) would end with e.g. a alphabetic char, you could use that as the finish trigger.... – Robert Ilbrink Aug 13 '12 at 17:38
  • It is an interesting thought; really, it just needs to keep track of additional modifier keys and batch send whenever =any= non-modifier is pressed (e.g. C-M-e or C-M-\ or C-u C-c . etc.). It could be like a ctrl lock key, and batch send repeatedly until toggled or term'd by a finish key. – assem Aug 14 '12 at 05:47
1

Have the script send{Ctrl down}
and then set a timer to run a subroutine after a desired amount of time (600ms in the example)
(the - makes it only run once)
to send {Ctrl up}:

sc1F1::
Sendinput, {Ctrl Down}
SetTimer, Reset, -600
Return

Reset:
Sendinput, {Ctrl Up}
Return

→SetTimer←


If you wanted to make it a toggle button,
i.e press it once and x sends Control + A,
then press it again to return x to normal behavior:

sc1F1::Flag:=!Flag

#If Flag
x::Sendinput, ^a
a::Sendinput, test
#If

The value of variable Flag is reversed with every press of sc1F1,
i.e. Flag is either set to 1 or 0.
#If Flag is shorthand for #If Flag = 1
This example requires Autohotkey_L (newer/recommended version) because it uses the #If command.

Using AHK basic it would look like:

sc1F1::Flag:=!Flag

$x::
if Flag
    Send, ^a
Else
    Send, x
Return

Other options/examples using
Capslock in place of sc1F1
:

You could try using & if you just want to use the button as a modifier.
This example turns Capslock into a modifier (the first line keeps the capslock light off):

SetCapsLockState, AlwaysOff

capslock & x::traytip,, %a_thishotkey%

If you want Capslock to send something when pressed alone
you will need to add something like:

capslock::Send, something

and then that will only then 'something' on the release of Capslock.

→Additional information←


Here is an example where X and A perform differently if Capslock is physically ("p") held down:

SetCapsLockState, AlwaysOff
#If GetKeystate("capslock","p")
x::traytip,, %a_thishotkey%
a::traytip,, %a_thishotkey%
#If

You could also try setting a variable ("Flag"),
and then clearing it with a timer.

capslock::
Flag := 1
SetTimer, Reset, 600
Return

Reset:
Flag := 0
Return

#If Flag
x::Sendinput, ^a
a::Sendinput, test
#If

Manual reference:
#If
GetKeyState()


Another option is installing a keyboard hook.
Then you can check what the last pressed key was with the built-in variable: a_priorkey

#InstallKeybdhook

x::
if (a_priorkey = "Capslock") {
    Traytip,, %a_thishotkey%
} Return

→More on built-in variables←


If all else fails you could try:
Remapping via the Registry's "Scancode Map"

Honest Abe
  • 8,430
  • 4
  • 49
  • 64
  • @abe Correct, it doesn't work as intended. It looks like as far as AutoHotkey goes, some sort of time/delay solution (or termination key like Robert suggested) is the best I can hope for. – assem Aug 14 '12 at 05:36
  • @abe Yup, just tested - traytip never appears. Updated original post; also, for your flag situation, I need to support pretty much any key that is pressed. Ctrl+anything along with Ctrl+[alt/shift]+anything. I think that's why Robert suggested that approach. – assem Aug 14 '12 at 07:24
  • @assem I added that link at the bottom of the answer, and also realized I put `SetTimer, Reset, 600` in the first example, which calls Reset constantly every 600ms. `SetTimer, Reset, -600` would only call it once. – Honest Abe Aug 15 '12 at 17:00
  • @abe Thanks for the timer update; the registry keymapping doesn't work as intended for this hanja key though. – assem Aug 17 '12 at 13:58
0

Maybe I didn't understand the question correctly, but I found key special codes for those keys and this did the trick for me:

SC11D:: RCtrl
SC138:: RAlt

Not sure who would use the Alt remap, but for the sake of completeness...

Works using Korean Microsoft IME on Win8.

Antimonit
  • 2,846
  • 23
  • 34