Remap a key to Ctrl and make it behave like Ctrl during text editing

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
5
down vote

favorite
2












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?







share|improve this question


























    up vote
    5
    down vote

    favorite
    2












    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?







    share|improve this question
























      up vote
      5
      down vote

      favorite
      2









      up vote
      5
      down vote

      favorite
      2






      2





      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?







      share|improve this question














      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?









      share|improve this question













      share|improve this question




      share|improve this question








      edited May 15 at 15:00









      Zanna

      47.9k13118227




      47.9k13118227










      asked May 15 at 13:08









      user1234567

      1711213




      1711213




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          +100










          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> ;





          share|improve this answer






















          • 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, 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










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          +100










          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> ;





          share|improve this answer






















          • 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, 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














          up vote
          2
          down vote



          +100










          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> ;





          share|improve this answer






















          • 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, 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












          up vote
          2
          down vote



          +100







          up vote
          2
          down vote



          +100




          +100




          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> ;





          share|improve this answer














          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> ;






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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, 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
















          • 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, 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















          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












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491