6

I have a Korean keyboard that looks like this:

enter image description here

Hanja (한자), just to the left of space, is so little utilized even when typing in Korean, yet it's in prime real real estate for my left thumb as an i3 window manager mod key. That will free up Alt for use in my code editor.

My question is: How can I turn the Hanja key into a modifier key?

I verified the key with xev:

KeyPress event, serial 32, synthetic NO, window 0x2200001,
    root 0x281, subw 0x0, time 11955968, (-132,626), root:(491,646),
    state 0x0, keycode 131 (keysym 0xff34, Hangul_Hanja), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0x2200001,
    root 0x281, subw 0x0, time 11955968, (-132,626), root:(491,646),
    state 0x20, keycode 131 (keysym 0xff34, Hangul_Hanja), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

Keycode 131 = 0x83

From the output of xmodmap, I see that mod3 is available.

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

I tried xmodmap -e "add mod3 = Hangul_Hanja" resulting in the following...

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        Hangul_Hanja (0x83)
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

... after adding set $mod Mod3 to my i3 config file and restarting, I ended up with no modifier key whatsoever, i.e. it didn't work.

Also, the Hanja key isn't behaving like the typical modifier key. If I press and hold the key it creates repeated keystrokes, whereas the typical modifier key does not.

I hope there's some keyboard experts in the house that can offer some of their expertise.

Linux Mint 18 (Cinnamon) i3 Window Manager

  • I am buying a Japanese Keyboard just to have access to these modifier keys. What did you end up using yours for by any chance? – William Aug 23 '18 at 5:00
3

X11 modifier handling is a bit peculiar. You can't take any key and declare it to be a modifier: some things have to be consistent between the modifier settings and the keysym settings.

The classic modifiers are Shift, Control, Alt, Meta, Hyper and Super (with two keysyms each, e.g. Shift_L and Shift_R) (plus Caps Lock and Num Lock which behave somewhat differently). Most applications won't work with other keysyms used as modifiers.

So to use the Hanja key as a modifier, make it be Hyper_L (for example).

keycode 131 = Hyper_L
remove Mod4 = Hyper_L
add Mod3 = Hyper_L

This makes the key no longer used as the Hanja key at all. There may be a way to keep both functions if you use XKB instead of xmodmap, but I don't know how.

  • I tried this with both Hyper_L and Hyper_R and it didn't work. Interestingly, however, I mapped the 'A' key to Hyper_R/L using the this method, and it worked fine, so there must be something peculiar about the Hanja key. – Verax Jul 23 '16 at 14:50
  • Could it possibly be because 131 is greater than 127? – Verax Jul 23 '16 at 15:13
  • Well, I was able to remap 133 to Hyper_R and then use that for Mod3 and it worked, so keycodes greater than 127 are fine (My suspicion for that came from superuser.com/a/431152/539822). The only thing I can think of is there must be something between X and i3 that's capturing the Hanja key. – Verax Jul 24 '16 at 0:54
  • Marking this as the answer because the method appears to be correct for keys in general which was the title of the question. The Hanja key may be getting trapped by an IME (input method editor) or some other process, and that is why that specific key doesn't work. – Verax Jul 24 '16 at 1:10
  • 2
    Just wanted to report back that all of my previous attempts were done in VirtualBox, but I recently installed Linux on the bare metal, and simply running xmodmap -e "add mod3 = Hangul_Hanja" gives me the effect I was looking for. There is no need to remap keys to Meta_L. – Verax Aug 30 '16 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.