Friday, June 5, 2015

linux - Remapping XF86_Back/Forward to Control/Alt in X



I'd like to rebind the XF86_Back and forward keys in X to control and alt respectively.




However, it seems that running




xmodmap -e "keycode 167 =Alt_L"
xmodmap -e "keycode 166 =Control_L"




isn't giving me the desired behaviour - I cannot type BACK + a to get to the start of line in a terminal, for example,even though xev is showing them as being correctly rebound.



EDIT:
The output from xev (with my comments as //comments) - alt works, control doesn't




// BACk
KeyPress event, serial 29, synthetic NO, window 0x2600001,
root 0x2bd, subw 0x0, time 3547970265, (983,501), root:(984,516),
state 0x10, keycode 166 (keysym 0xffe3, Control_L), same_screen YES,
XKeysymToKeycode returns keycode: 37
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False



KeyRelease event, serial 32, synthetic NO, window 0x2600001,

root 0x2bd, subw 0x0, time 3547970385, (983,501), root:(984,516),
state 0x10, keycode 166 (keysym 0xffe3, Control_L), same_screen YES,
XKeysymToKeycode returns keycode: 37
XLookupString gives 0 bytes:
XFilterEvent returns: False



// FORWARD
KeyPress event, serial 32, synthetic NO, window 0x2600001,
root 0x2bd, subw 0x0, time 3547974553, (983,501), root:(984,516),
state 0x10, keycode 167 (keysym 0xffe9, Alt_L), same_screen YES,

XKeysymToKeycode returns keycode: 64
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False



KeyRelease event, serial 32, synthetic NO, window 0x2600001,
root 0x2bd, subw 0x0, time 3547974713, (983,501), root:(984,516),
state 0x18, keycode 167 (keysym 0xffe9, Alt_L), same_screen YES,
XKeysymToKeycode returns keycode: 64
XLookupString gives 0 bytes:

XFilterEvent returns: False


Answer



Make sure that the Control_L keysym is bound to the "Control" modifier:



keycode 166 = Control_L
add Control = Control_L


To verify in xev, when you release the key, the reported state needs to have bit 0x4 set - i.e. if you have NumLock on, when you press the new "Control" key, you should have state 0x10, and when you release it, you should get state 0x14. Similarly for the new "Alt" key, which should change from 0x10 to 0x18 (also assuming NumLock is active - that's the 0x10 part).


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...