Remap a key to Ctrl and make it behave like Ctrl during text editing
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
5
down vote
favorite
I bought a fancy-looking mechanical keyboard in Korea. In general, it works really well except for one thing - even though it has Alt and Ctrl keys on its right side, these keys do not generate the same codes as a "regular" keyboard.
Long story short, Right Alt is the Hangul key (changes between Latin and Korean letters) and Ctrl is Hanja (converts between Hangul and "old" Korean characters). I wanted to use multiple layouts - Korean and my local one (Polish) and keep the best of both worlds - that means making Right Alt emit the keycode for Alt while typing Polish and for Hangul while typing in Korean.
Korean worked out of the box (since the keycodes are correct there), but Polish needed tweaks. I changed the layout (/usr/share/X11/xkb/symbols/pl
) by adding the following lines in the active xkb_symbols
section:
key <HNGL> [ ISO_Level3_Shift ] ;
key <HJCV> [ Control_R ] ;
And I have commented out the lines related to HNGL
and HJCV
in the "inet" layout, since these were overwriting my changes.
After these changes I got Alt working perfectly, but there was still a problem with Ctrl key not working correctly. In general it works, but when editing text, I should be able to e.g. delete one word by using Ctrl+Backspace combination and I'm unable to do so.
I have executed xset -r 131
in order to disable key repeating for this Ctrl/Hanja key but it still doesn't work like a real Ctrl
Here's the xev
output of remapped Hanja
:
KeyPress event, serial 34, synthetic NO, window 0x1000001,
root 0x13f, subw 0x0, time 49086462, (88,89), root:(3928,141),
state 0x10, keycode 131 (keysym 0xffe4, Control_R), same_screen YES,
XKeysymToKeycode returns keycode: 105
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
And here's a regular Ctrl (from other keyboard):
KeyPress event, serial 39, synthetic NO, window 0x1000001,
root 0x13f, subw 0x0, time 49144922, (616,377), root:(4456,429),
state 0x10, keycode 105 (keysym 0xffe4, Control_R), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
Is there anything I can change to make my system treat that key as a full-blown Ctrl?
keyboard keyboard-layout xkb
add a comment |Â
up vote
5
down vote
favorite
I bought a fancy-looking mechanical keyboard in Korea. In general, it works really well except for one thing - even though it has Alt and Ctrl keys on its right side, these keys do not generate the same codes as a "regular" keyboard.
Long story short, Right Alt is the Hangul key (changes between Latin and Korean letters) and Ctrl is Hanja (converts between Hangul and "old" Korean characters). I wanted to use multiple layouts - Korean and my local one (Polish) and keep the best of both worlds - that means making Right Alt emit the keycode for Alt while typing Polish and for Hangul while typing in Korean.
Korean worked out of the box (since the keycodes are correct there), but Polish needed tweaks. I changed the layout (/usr/share/X11/xkb/symbols/pl
) by adding the following lines in the active xkb_symbols
section:
key <HNGL> [ ISO_Level3_Shift ] ;
key <HJCV> [ Control_R ] ;
And I have commented out the lines related to HNGL
and HJCV
in the "inet" layout, since these were overwriting my changes.
After these changes I got Alt working perfectly, but there was still a problem with Ctrl key not working correctly. In general it works, but when editing text, I should be able to e.g. delete one word by using Ctrl+Backspace combination and I'm unable to do so.
I have executed xset -r 131
in order to disable key repeating for this Ctrl/Hanja key but it still doesn't work like a real Ctrl
Here's the xev
output of remapped Hanja
:
KeyPress event, serial 34, synthetic NO, window 0x1000001,
root 0x13f, subw 0x0, time 49086462, (88,89), root:(3928,141),
state 0x10, keycode 131 (keysym 0xffe4, Control_R), same_screen YES,
XKeysymToKeycode returns keycode: 105
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
And here's a regular Ctrl (from other keyboard):
KeyPress event, serial 39, synthetic NO, window 0x1000001,
root 0x13f, subw 0x0, time 49144922, (616,377), root:(4456,429),
state 0x10, keycode 105 (keysym 0xffe4, Control_R), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
Is there anything I can change to make my system treat that key as a full-blown Ctrl?
keyboard keyboard-layout xkb
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I bought a fancy-looking mechanical keyboard in Korea. In general, it works really well except for one thing - even though it has Alt and Ctrl keys on its right side, these keys do not generate the same codes as a "regular" keyboard.
Long story short, Right Alt is the Hangul key (changes between Latin and Korean letters) and Ctrl is Hanja (converts between Hangul and "old" Korean characters). I wanted to use multiple layouts - Korean and my local one (Polish) and keep the best of both worlds - that means making Right Alt emit the keycode for Alt while typing Polish and for Hangul while typing in Korean.
Korean worked out of the box (since the keycodes are correct there), but Polish needed tweaks. I changed the layout (/usr/share/X11/xkb/symbols/pl
) by adding the following lines in the active xkb_symbols
section:
key <HNGL> [ ISO_Level3_Shift ] ;
key <HJCV> [ Control_R ] ;
And I have commented out the lines related to HNGL
and HJCV
in the "inet" layout, since these were overwriting my changes.
After these changes I got Alt working perfectly, but there was still a problem with Ctrl key not working correctly. In general it works, but when editing text, I should be able to e.g. delete one word by using Ctrl+Backspace combination and I'm unable to do so.
I have executed xset -r 131
in order to disable key repeating for this Ctrl/Hanja key but it still doesn't work like a real Ctrl
Here's the xev
output of remapped Hanja
:
KeyPress event, serial 34, synthetic NO, window 0x1000001,
root 0x13f, subw 0x0, time 49086462, (88,89), root:(3928,141),
state 0x10, keycode 131 (keysym 0xffe4, Control_R), same_screen YES,
XKeysymToKeycode returns keycode: 105
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
And here's a regular Ctrl (from other keyboard):
KeyPress event, serial 39, synthetic NO, window 0x1000001,
root 0x13f, subw 0x0, time 49144922, (616,377), root:(4456,429),
state 0x10, keycode 105 (keysym 0xffe4, Control_R), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
Is there anything I can change to make my system treat that key as a full-blown Ctrl?
keyboard keyboard-layout xkb
I bought a fancy-looking mechanical keyboard in Korea. In general, it works really well except for one thing - even though it has Alt and Ctrl keys on its right side, these keys do not generate the same codes as a "regular" keyboard.
Long story short, Right Alt is the Hangul key (changes between Latin and Korean letters) and Ctrl is Hanja (converts between Hangul and "old" Korean characters). I wanted to use multiple layouts - Korean and my local one (Polish) and keep the best of both worlds - that means making Right Alt emit the keycode for Alt while typing Polish and for Hangul while typing in Korean.
Korean worked out of the box (since the keycodes are correct there), but Polish needed tweaks. I changed the layout (/usr/share/X11/xkb/symbols/pl
) by adding the following lines in the active xkb_symbols
section:
key <HNGL> [ ISO_Level3_Shift ] ;
key <HJCV> [ Control_R ] ;
And I have commented out the lines related to HNGL
and HJCV
in the "inet" layout, since these were overwriting my changes.
After these changes I got Alt working perfectly, but there was still a problem with Ctrl key not working correctly. In general it works, but when editing text, I should be able to e.g. delete one word by using Ctrl+Backspace combination and I'm unable to do so.
I have executed xset -r 131
in order to disable key repeating for this Ctrl/Hanja key but it still doesn't work like a real Ctrl
Here's the xev
output of remapped Hanja
:
KeyPress event, serial 34, synthetic NO, window 0x1000001,
root 0x13f, subw 0x0, time 49086462, (88,89), root:(3928,141),
state 0x10, keycode 131 (keysym 0xffe4, Control_R), same_screen YES,
XKeysymToKeycode returns keycode: 105
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
And here's a regular Ctrl (from other keyboard):
KeyPress event, serial 39, synthetic NO, window 0x1000001,
root 0x13f, subw 0x0, time 49144922, (616,377), root:(4456,429),
state 0x10, keycode 105 (keysym 0xffe4, Control_R), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
Is there anything I can change to make my system treat that key as a full-blown Ctrl?
keyboard keyboard-layout xkb
edited May 15 at 15:00
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
47.9k13118227
47.9k13118227
asked May 15 at 13:08
user1234567
1711213
1711213
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Assigning a key to another is unique when the key is a modifier.
This answer has a good explanation:
The action, when it is a modifier action such as this, changes the current modifier state, which (simply put) is a set of flags recorded in the operating system that record what modifiers are currently "on". [This record] influences what action further keypresses map to.
And so when you are trying to map your key, it is being mapped as a regular key and losing information which specifies how it behaves when multiple keys are pressed.
To demonstrate, run xmodmap
. Note that there are two default keys (Control_L and Control_R) mapped to the control modifier. If you run xmodmap -e 'keycode 131 = Control_L'
and then xmodmap
, the control modifier should still have two keys, so your key isn't being recognized as a modifier.
To map as a modifier:
Clear the modifier key control
xmodmap -e 'clear control'
Add the keycode for the Hanja key
xmodmap -e 'keycode 131 = Control_L'
Lastly, add back the default modifiers:
xmodmap -e 'add control = Control_L'
xmodmap -e 'add control = Control_R'
Now, if you were to run xmodmap again, you will notice a new key has been added for the modifier control, and it should work correctly now.
Here is a link to official Arch Linux instructions on reassigning modifiers to keys on your keyboard.
edit:
for persistent changes, add to /usr/share/X11/xkb/symbols/pl
:
key <HJCV> [ Control_L ] ;
modifier_map Control Control_L, Control_R, <HJCV> ;
That indeed works! Just one follow up - chaning the keyboard layout resets the xmodmap settings - is there any way I can run a script after layout change or put these into xkb layout? All the instructions I have found assume that I'll use just one layout.
â user1234567
May 24 at 7:50
1
Yes I see, addingkey <HJCV> [ Control_L ] ;
andmodifier_map Control Control_L, Control_R, <HJCV> ;
to/usr/share/X11/xkb/symbols/pl
and recaching/rebooting should fix this.
â jackw11111
May 24 at 9:43
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Assigning a key to another is unique when the key is a modifier.
This answer has a good explanation:
The action, when it is a modifier action such as this, changes the current modifier state, which (simply put) is a set of flags recorded in the operating system that record what modifiers are currently "on". [This record] influences what action further keypresses map to.
And so when you are trying to map your key, it is being mapped as a regular key and losing information which specifies how it behaves when multiple keys are pressed.
To demonstrate, run xmodmap
. Note that there are two default keys (Control_L and Control_R) mapped to the control modifier. If you run xmodmap -e 'keycode 131 = Control_L'
and then xmodmap
, the control modifier should still have two keys, so your key isn't being recognized as a modifier.
To map as a modifier:
Clear the modifier key control
xmodmap -e 'clear control'
Add the keycode for the Hanja key
xmodmap -e 'keycode 131 = Control_L'
Lastly, add back the default modifiers:
xmodmap -e 'add control = Control_L'
xmodmap -e 'add control = Control_R'
Now, if you were to run xmodmap again, you will notice a new key has been added for the modifier control, and it should work correctly now.
Here is a link to official Arch Linux instructions on reassigning modifiers to keys on your keyboard.
edit:
for persistent changes, add to /usr/share/X11/xkb/symbols/pl
:
key <HJCV> [ Control_L ] ;
modifier_map Control Control_L, Control_R, <HJCV> ;
That indeed works! Just one follow up - chaning the keyboard layout resets the xmodmap settings - is there any way I can run a script after layout change or put these into xkb layout? All the instructions I have found assume that I'll use just one layout.
â user1234567
May 24 at 7:50
1
Yes I see, addingkey <HJCV> [ Control_L ] ;
andmodifier_map Control Control_L, Control_R, <HJCV> ;
to/usr/share/X11/xkb/symbols/pl
and recaching/rebooting should fix this.
â jackw11111
May 24 at 9:43
add a comment |Â
up vote
2
down vote
Assigning a key to another is unique when the key is a modifier.
This answer has a good explanation:
The action, when it is a modifier action such as this, changes the current modifier state, which (simply put) is a set of flags recorded in the operating system that record what modifiers are currently "on". [This record] influences what action further keypresses map to.
And so when you are trying to map your key, it is being mapped as a regular key and losing information which specifies how it behaves when multiple keys are pressed.
To demonstrate, run xmodmap
. Note that there are two default keys (Control_L and Control_R) mapped to the control modifier. If you run xmodmap -e 'keycode 131 = Control_L'
and then xmodmap
, the control modifier should still have two keys, so your key isn't being recognized as a modifier.
To map as a modifier:
Clear the modifier key control
xmodmap -e 'clear control'
Add the keycode for the Hanja key
xmodmap -e 'keycode 131 = Control_L'
Lastly, add back the default modifiers:
xmodmap -e 'add control = Control_L'
xmodmap -e 'add control = Control_R'
Now, if you were to run xmodmap again, you will notice a new key has been added for the modifier control, and it should work correctly now.
Here is a link to official Arch Linux instructions on reassigning modifiers to keys on your keyboard.
edit:
for persistent changes, add to /usr/share/X11/xkb/symbols/pl
:
key <HJCV> [ Control_L ] ;
modifier_map Control Control_L, Control_R, <HJCV> ;
That indeed works! Just one follow up - chaning the keyboard layout resets the xmodmap settings - is there any way I can run a script after layout change or put these into xkb layout? All the instructions I have found assume that I'll use just one layout.
â user1234567
May 24 at 7:50
1
Yes I see, addingkey <HJCV> [ Control_L ] ;
andmodifier_map Control Control_L, Control_R, <HJCV> ;
to/usr/share/X11/xkb/symbols/pl
and recaching/rebooting should fix this.
â jackw11111
May 24 at 9:43
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Assigning a key to another is unique when the key is a modifier.
This answer has a good explanation:
The action, when it is a modifier action such as this, changes the current modifier state, which (simply put) is a set of flags recorded in the operating system that record what modifiers are currently "on". [This record] influences what action further keypresses map to.
And so when you are trying to map your key, it is being mapped as a regular key and losing information which specifies how it behaves when multiple keys are pressed.
To demonstrate, run xmodmap
. Note that there are two default keys (Control_L and Control_R) mapped to the control modifier. If you run xmodmap -e 'keycode 131 = Control_L'
and then xmodmap
, the control modifier should still have two keys, so your key isn't being recognized as a modifier.
To map as a modifier:
Clear the modifier key control
xmodmap -e 'clear control'
Add the keycode for the Hanja key
xmodmap -e 'keycode 131 = Control_L'
Lastly, add back the default modifiers:
xmodmap -e 'add control = Control_L'
xmodmap -e 'add control = Control_R'
Now, if you were to run xmodmap again, you will notice a new key has been added for the modifier control, and it should work correctly now.
Here is a link to official Arch Linux instructions on reassigning modifiers to keys on your keyboard.
edit:
for persistent changes, add to /usr/share/X11/xkb/symbols/pl
:
key <HJCV> [ Control_L ] ;
modifier_map Control Control_L, Control_R, <HJCV> ;
Assigning a key to another is unique when the key is a modifier.
This answer has a good explanation:
The action, when it is a modifier action such as this, changes the current modifier state, which (simply put) is a set of flags recorded in the operating system that record what modifiers are currently "on". [This record] influences what action further keypresses map to.
And so when you are trying to map your key, it is being mapped as a regular key and losing information which specifies how it behaves when multiple keys are pressed.
To demonstrate, run xmodmap
. Note that there are two default keys (Control_L and Control_R) mapped to the control modifier. If you run xmodmap -e 'keycode 131 = Control_L'
and then xmodmap
, the control modifier should still have two keys, so your key isn't being recognized as a modifier.
To map as a modifier:
Clear the modifier key control
xmodmap -e 'clear control'
Add the keycode for the Hanja key
xmodmap -e 'keycode 131 = Control_L'
Lastly, add back the default modifiers:
xmodmap -e 'add control = Control_L'
xmodmap -e 'add control = Control_R'
Now, if you were to run xmodmap again, you will notice a new key has been added for the modifier control, and it should work correctly now.
Here is a link to official Arch Linux instructions on reassigning modifiers to keys on your keyboard.
edit:
for persistent changes, add to /usr/share/X11/xkb/symbols/pl
:
key <HJCV> [ Control_L ] ;
modifier_map Control Control_L, Control_R, <HJCV> ;
edited May 25 at 6:36
answered May 24 at 2:37
jackw11111
33117
33117
That indeed works! Just one follow up - chaning the keyboard layout resets the xmodmap settings - is there any way I can run a script after layout change or put these into xkb layout? All the instructions I have found assume that I'll use just one layout.
â user1234567
May 24 at 7:50
1
Yes I see, addingkey <HJCV> [ Control_L ] ;
andmodifier_map Control Control_L, Control_R, <HJCV> ;
to/usr/share/X11/xkb/symbols/pl
and recaching/rebooting should fix this.
â jackw11111
May 24 at 9:43
add a comment |Â
That indeed works! Just one follow up - chaning the keyboard layout resets the xmodmap settings - is there any way I can run a script after layout change or put these into xkb layout? All the instructions I have found assume that I'll use just one layout.
â user1234567
May 24 at 7:50
1
Yes I see, addingkey <HJCV> [ Control_L ] ;
andmodifier_map Control Control_L, Control_R, <HJCV> ;
to/usr/share/X11/xkb/symbols/pl
and recaching/rebooting should fix this.
â jackw11111
May 24 at 9:43
That indeed works! Just one follow up - chaning the keyboard layout resets the xmodmap settings - is there any way I can run a script after layout change or put these into xkb layout? All the instructions I have found assume that I'll use just one layout.
â user1234567
May 24 at 7:50
That indeed works! Just one follow up - chaning the keyboard layout resets the xmodmap settings - is there any way I can run a script after layout change or put these into xkb layout? All the instructions I have found assume that I'll use just one layout.
â user1234567
May 24 at 7:50
1
1
Yes I see, adding
key <HJCV> [ Control_L ] ;
and modifier_map Control Control_L, Control_R, <HJCV> ;
to /usr/share/X11/xkb/symbols/pl
and recaching/rebooting should fix this.â jackw11111
May 24 at 9:43
Yes I see, adding
key <HJCV> [ Control_L ] ;
and modifier_map Control Control_L, Control_R, <HJCV> ;
to /usr/share/X11/xkb/symbols/pl
and recaching/rebooting should fix this.â jackw11111
May 24 at 9:43
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036521%2fremap-a-key-to-ctrl-and-make-it-behave-like-ctrl-during-text-editing%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password