How to map caps lock to arrow keys?

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








up vote
5
down vote

favorite












I am trying to map Caps Lock to the Down arrow key and Caps Lock with a shift modifier to the up arrow key.



I've tried using xmodmap with the following input file:



remove Lock = Caps_Lock
keycode 66 = Down Up


Pressing caps lock does work for sending the down arrow key, but pressing caps lock + shift does not send Up.



What am I doing wrong?










share|improve this question



























    up vote
    5
    down vote

    favorite












    I am trying to map Caps Lock to the Down arrow key and Caps Lock with a shift modifier to the up arrow key.



    I've tried using xmodmap with the following input file:



    remove Lock = Caps_Lock
    keycode 66 = Down Up


    Pressing caps lock does work for sending the down arrow key, but pressing caps lock + shift does not send Up.



    What am I doing wrong?










    share|improve this question

























      up vote
      5
      down vote

      favorite









      up vote
      5
      down vote

      favorite











      I am trying to map Caps Lock to the Down arrow key and Caps Lock with a shift modifier to the up arrow key.



      I've tried using xmodmap with the following input file:



      remove Lock = Caps_Lock
      keycode 66 = Down Up


      Pressing caps lock does work for sending the down arrow key, but pressing caps lock + shift does not send Up.



      What am I doing wrong?










      share|improve this question















      I am trying to map Caps Lock to the Down arrow key and Caps Lock with a shift modifier to the up arrow key.



      I've tried using xmodmap with the following input file:



      remove Lock = Caps_Lock
      keycode 66 = Down Up


      Pressing caps lock does work for sending the down arrow key, but pressing caps lock + shift does not send Up.



      What am I doing wrong?







      16.04 keyboard xmodmap xkb






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 6 at 9:42









      ukos

      476114




      476114










      asked Jan 28 at 6:48









      Jared Beach

      786




      786




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted
          +50










          There will be a lot to the technical details to this solution. Feel free to jump to the layout file section if you do not care about the problem but only on the solution.



          xmodmap



          Moving up and down via CAPS and Shift+CAPS works on my system with the given .Xmodmap as expected.



          You check whether your settings are actually in affect by calling



          $ xmodmap -pk | grep ^\s*66
          66 0xffe5 (Caps_Lock) 0x0000 (NoSymbol) 0xffe5 (Caps_Lock)
          $ setxkbmap -layout us && xmodmap ~/.Xmodmap
          $ xmodmap -pk | grep ^\s*66
          66 0xff54 (Down) 0xff52 (Up)


          the LEVEL2 Modifier



          There is another (real) problem to your question that comes next:



          The LEVEL2 <SHIFT> modifier which is activated by pressing the Shift button is there to visually mark characters in a text editor when moving through the lines with the arrow keys. If you assign <UP> ↑ to the second level of <CAPS>, what you are effectively doing is pressing Shift+↑. You have to deactivate the Shift modifier just for that scenario. Afaik you can not do this using xmodmap.



          redirecting LEVEL2 Modifier



          The "real way" of modifying key maps is with xkb. I found the solution on an old xorg mailing list. The LEVEL2 of Caps has to get redirected to the ↑(<UP>) key (The Up-Key btw has only one level.) On X.org you can deactivating the Shift modifier during redirect with the built-in function RedirectKey(key=<UP>, clearmods=Shift). clearmods "releases" the Shift modifier before the the key is actually "pressed".



          layout file



          The simplest way to activate the behavior is to create a new layout file:



          /usr/share/X11/xkb/symbols/capslockarrow



          default partial xkb_symbols "basic" 

          include "de(basic)"
          include "shift(both_capslock_cancel)"

          key <CAPS>
          type[Group1] = "TWO_LEVEL",
          symbols[Group1] = [ Down, NoSymbol ],
          actions[Group1] = [ NoAction(), RedirectKey(key=<UP>, clearmods=Shift) ]
          ;
          ;


          activate the new layout with



          setxkbmap capslockarrow


          Notes on the layout file



          • The new layout file derives from de(basic). That is the layout for the standard german keyboard. You can add any other layout here like us(basic) or us(euro). see /usr/share/X11/xkb/symbols/ to get a glance of what is possible. The two letter code is the filename and in brackets is the respective xkb_symbols definition from the file.


          • You would not have a caps key modifier anymore. Therefore I added a sort of replacement for Caps: shift(both_capslock_cancel) By pressing both LSHIFT and RSHIFT together, you can activate CAPS Lock and you release the Lock again with any other press of a Shift key.


          • If anyone is wondering why I did not use a new type definition for that: I simply could not release the Shift modifier before the action of the Up Key was triggered. Releasing the Shift key though should be possible by explicitly calling preserve[Shift] = None in a spearated xkb_types.


          • As stated in the comments below, Wayland will also rely on XKB but will not allow redirections.






          share|improve this answer






















          • wayland uses XKB (via xkbcommon, not the X11 library), so modified XKB options will work. (at least if they're placed in the system XKB files.) xmodmap will not function.
            – quixotic
            Feb 4 at 0:32










          • Thanks for the explanation. I figured I was sending shift + up. Now I can see I am when I highlight text in chrome. I guess the real question is how do I disable the level 2 switch, only for this scenario
            – Jared Beach
            Feb 4 at 4:40










          • I found the solution and updated my post.
            – ukos
            Feb 5 at 1:57










          • nice solution, thanks. i don't know if this will work in contexts like wayland that use xkbcommon -- redirect actions are listed among the current incompatibilities, though that could be remedied in the future.
            – quixotic
            Feb 6 at 8:50






          • 1




            @jared-beach done
            – ukos
            Feb 11 at 1:02










          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%2f1000594%2fhow-to-map-caps-lock-to-arrow-keys%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
          3
          down vote



          accepted
          +50










          There will be a lot to the technical details to this solution. Feel free to jump to the layout file section if you do not care about the problem but only on the solution.



          xmodmap



          Moving up and down via CAPS and Shift+CAPS works on my system with the given .Xmodmap as expected.



          You check whether your settings are actually in affect by calling



          $ xmodmap -pk | grep ^\s*66
          66 0xffe5 (Caps_Lock) 0x0000 (NoSymbol) 0xffe5 (Caps_Lock)
          $ setxkbmap -layout us && xmodmap ~/.Xmodmap
          $ xmodmap -pk | grep ^\s*66
          66 0xff54 (Down) 0xff52 (Up)


          the LEVEL2 Modifier



          There is another (real) problem to your question that comes next:



          The LEVEL2 <SHIFT> modifier which is activated by pressing the Shift button is there to visually mark characters in a text editor when moving through the lines with the arrow keys. If you assign <UP> ↑ to the second level of <CAPS>, what you are effectively doing is pressing Shift+↑. You have to deactivate the Shift modifier just for that scenario. Afaik you can not do this using xmodmap.



          redirecting LEVEL2 Modifier



          The "real way" of modifying key maps is with xkb. I found the solution on an old xorg mailing list. The LEVEL2 of Caps has to get redirected to the ↑(<UP>) key (The Up-Key btw has only one level.) On X.org you can deactivating the Shift modifier during redirect with the built-in function RedirectKey(key=<UP>, clearmods=Shift). clearmods "releases" the Shift modifier before the the key is actually "pressed".



          layout file



          The simplest way to activate the behavior is to create a new layout file:



          /usr/share/X11/xkb/symbols/capslockarrow



          default partial xkb_symbols "basic" 

          include "de(basic)"
          include "shift(both_capslock_cancel)"

          key <CAPS>
          type[Group1] = "TWO_LEVEL",
          symbols[Group1] = [ Down, NoSymbol ],
          actions[Group1] = [ NoAction(), RedirectKey(key=<UP>, clearmods=Shift) ]
          ;
          ;


          activate the new layout with



          setxkbmap capslockarrow


          Notes on the layout file



          • The new layout file derives from de(basic). That is the layout for the standard german keyboard. You can add any other layout here like us(basic) or us(euro). see /usr/share/X11/xkb/symbols/ to get a glance of what is possible. The two letter code is the filename and in brackets is the respective xkb_symbols definition from the file.


          • You would not have a caps key modifier anymore. Therefore I added a sort of replacement for Caps: shift(both_capslock_cancel) By pressing both LSHIFT and RSHIFT together, you can activate CAPS Lock and you release the Lock again with any other press of a Shift key.


          • If anyone is wondering why I did not use a new type definition for that: I simply could not release the Shift modifier before the action of the Up Key was triggered. Releasing the Shift key though should be possible by explicitly calling preserve[Shift] = None in a spearated xkb_types.


          • As stated in the comments below, Wayland will also rely on XKB but will not allow redirections.






          share|improve this answer






















          • wayland uses XKB (via xkbcommon, not the X11 library), so modified XKB options will work. (at least if they're placed in the system XKB files.) xmodmap will not function.
            – quixotic
            Feb 4 at 0:32










          • Thanks for the explanation. I figured I was sending shift + up. Now I can see I am when I highlight text in chrome. I guess the real question is how do I disable the level 2 switch, only for this scenario
            – Jared Beach
            Feb 4 at 4:40










          • I found the solution and updated my post.
            – ukos
            Feb 5 at 1:57










          • nice solution, thanks. i don't know if this will work in contexts like wayland that use xkbcommon -- redirect actions are listed among the current incompatibilities, though that could be remedied in the future.
            – quixotic
            Feb 6 at 8:50






          • 1




            @jared-beach done
            – ukos
            Feb 11 at 1:02














          up vote
          3
          down vote



          accepted
          +50










          There will be a lot to the technical details to this solution. Feel free to jump to the layout file section if you do not care about the problem but only on the solution.



          xmodmap



          Moving up and down via CAPS and Shift+CAPS works on my system with the given .Xmodmap as expected.



          You check whether your settings are actually in affect by calling



          $ xmodmap -pk | grep ^\s*66
          66 0xffe5 (Caps_Lock) 0x0000 (NoSymbol) 0xffe5 (Caps_Lock)
          $ setxkbmap -layout us && xmodmap ~/.Xmodmap
          $ xmodmap -pk | grep ^\s*66
          66 0xff54 (Down) 0xff52 (Up)


          the LEVEL2 Modifier



          There is another (real) problem to your question that comes next:



          The LEVEL2 <SHIFT> modifier which is activated by pressing the Shift button is there to visually mark characters in a text editor when moving through the lines with the arrow keys. If you assign <UP> ↑ to the second level of <CAPS>, what you are effectively doing is pressing Shift+↑. You have to deactivate the Shift modifier just for that scenario. Afaik you can not do this using xmodmap.



          redirecting LEVEL2 Modifier



          The "real way" of modifying key maps is with xkb. I found the solution on an old xorg mailing list. The LEVEL2 of Caps has to get redirected to the ↑(<UP>) key (The Up-Key btw has only one level.) On X.org you can deactivating the Shift modifier during redirect with the built-in function RedirectKey(key=<UP>, clearmods=Shift). clearmods "releases" the Shift modifier before the the key is actually "pressed".



          layout file



          The simplest way to activate the behavior is to create a new layout file:



          /usr/share/X11/xkb/symbols/capslockarrow



          default partial xkb_symbols "basic" 

          include "de(basic)"
          include "shift(both_capslock_cancel)"

          key <CAPS>
          type[Group1] = "TWO_LEVEL",
          symbols[Group1] = [ Down, NoSymbol ],
          actions[Group1] = [ NoAction(), RedirectKey(key=<UP>, clearmods=Shift) ]
          ;
          ;


          activate the new layout with



          setxkbmap capslockarrow


          Notes on the layout file



          • The new layout file derives from de(basic). That is the layout for the standard german keyboard. You can add any other layout here like us(basic) or us(euro). see /usr/share/X11/xkb/symbols/ to get a glance of what is possible. The two letter code is the filename and in brackets is the respective xkb_symbols definition from the file.


          • You would not have a caps key modifier anymore. Therefore I added a sort of replacement for Caps: shift(both_capslock_cancel) By pressing both LSHIFT and RSHIFT together, you can activate CAPS Lock and you release the Lock again with any other press of a Shift key.


          • If anyone is wondering why I did not use a new type definition for that: I simply could not release the Shift modifier before the action of the Up Key was triggered. Releasing the Shift key though should be possible by explicitly calling preserve[Shift] = None in a spearated xkb_types.


          • As stated in the comments below, Wayland will also rely on XKB but will not allow redirections.






          share|improve this answer






















          • wayland uses XKB (via xkbcommon, not the X11 library), so modified XKB options will work. (at least if they're placed in the system XKB files.) xmodmap will not function.
            – quixotic
            Feb 4 at 0:32










          • Thanks for the explanation. I figured I was sending shift + up. Now I can see I am when I highlight text in chrome. I guess the real question is how do I disable the level 2 switch, only for this scenario
            – Jared Beach
            Feb 4 at 4:40










          • I found the solution and updated my post.
            – ukos
            Feb 5 at 1:57










          • nice solution, thanks. i don't know if this will work in contexts like wayland that use xkbcommon -- redirect actions are listed among the current incompatibilities, though that could be remedied in the future.
            – quixotic
            Feb 6 at 8:50






          • 1




            @jared-beach done
            – ukos
            Feb 11 at 1:02












          up vote
          3
          down vote



          accepted
          +50







          up vote
          3
          down vote



          accepted
          +50




          +50




          There will be a lot to the technical details to this solution. Feel free to jump to the layout file section if you do not care about the problem but only on the solution.



          xmodmap



          Moving up and down via CAPS and Shift+CAPS works on my system with the given .Xmodmap as expected.



          You check whether your settings are actually in affect by calling



          $ xmodmap -pk | grep ^\s*66
          66 0xffe5 (Caps_Lock) 0x0000 (NoSymbol) 0xffe5 (Caps_Lock)
          $ setxkbmap -layout us && xmodmap ~/.Xmodmap
          $ xmodmap -pk | grep ^\s*66
          66 0xff54 (Down) 0xff52 (Up)


          the LEVEL2 Modifier



          There is another (real) problem to your question that comes next:



          The LEVEL2 <SHIFT> modifier which is activated by pressing the Shift button is there to visually mark characters in a text editor when moving through the lines with the arrow keys. If you assign <UP> ↑ to the second level of <CAPS>, what you are effectively doing is pressing Shift+↑. You have to deactivate the Shift modifier just for that scenario. Afaik you can not do this using xmodmap.



          redirecting LEVEL2 Modifier



          The "real way" of modifying key maps is with xkb. I found the solution on an old xorg mailing list. The LEVEL2 of Caps has to get redirected to the ↑(<UP>) key (The Up-Key btw has only one level.) On X.org you can deactivating the Shift modifier during redirect with the built-in function RedirectKey(key=<UP>, clearmods=Shift). clearmods "releases" the Shift modifier before the the key is actually "pressed".



          layout file



          The simplest way to activate the behavior is to create a new layout file:



          /usr/share/X11/xkb/symbols/capslockarrow



          default partial xkb_symbols "basic" 

          include "de(basic)"
          include "shift(both_capslock_cancel)"

          key <CAPS>
          type[Group1] = "TWO_LEVEL",
          symbols[Group1] = [ Down, NoSymbol ],
          actions[Group1] = [ NoAction(), RedirectKey(key=<UP>, clearmods=Shift) ]
          ;
          ;


          activate the new layout with



          setxkbmap capslockarrow


          Notes on the layout file



          • The new layout file derives from de(basic). That is the layout for the standard german keyboard. You can add any other layout here like us(basic) or us(euro). see /usr/share/X11/xkb/symbols/ to get a glance of what is possible. The two letter code is the filename and in brackets is the respective xkb_symbols definition from the file.


          • You would not have a caps key modifier anymore. Therefore I added a sort of replacement for Caps: shift(both_capslock_cancel) By pressing both LSHIFT and RSHIFT together, you can activate CAPS Lock and you release the Lock again with any other press of a Shift key.


          • If anyone is wondering why I did not use a new type definition for that: I simply could not release the Shift modifier before the action of the Up Key was triggered. Releasing the Shift key though should be possible by explicitly calling preserve[Shift] = None in a spearated xkb_types.


          • As stated in the comments below, Wayland will also rely on XKB but will not allow redirections.






          share|improve this answer














          There will be a lot to the technical details to this solution. Feel free to jump to the layout file section if you do not care about the problem but only on the solution.



          xmodmap



          Moving up and down via CAPS and Shift+CAPS works on my system with the given .Xmodmap as expected.



          You check whether your settings are actually in affect by calling



          $ xmodmap -pk | grep ^\s*66
          66 0xffe5 (Caps_Lock) 0x0000 (NoSymbol) 0xffe5 (Caps_Lock)
          $ setxkbmap -layout us && xmodmap ~/.Xmodmap
          $ xmodmap -pk | grep ^\s*66
          66 0xff54 (Down) 0xff52 (Up)


          the LEVEL2 Modifier



          There is another (real) problem to your question that comes next:



          The LEVEL2 <SHIFT> modifier which is activated by pressing the Shift button is there to visually mark characters in a text editor when moving through the lines with the arrow keys. If you assign <UP> ↑ to the second level of <CAPS>, what you are effectively doing is pressing Shift+↑. You have to deactivate the Shift modifier just for that scenario. Afaik you can not do this using xmodmap.



          redirecting LEVEL2 Modifier



          The "real way" of modifying key maps is with xkb. I found the solution on an old xorg mailing list. The LEVEL2 of Caps has to get redirected to the ↑(<UP>) key (The Up-Key btw has only one level.) On X.org you can deactivating the Shift modifier during redirect with the built-in function RedirectKey(key=<UP>, clearmods=Shift). clearmods "releases" the Shift modifier before the the key is actually "pressed".



          layout file



          The simplest way to activate the behavior is to create a new layout file:



          /usr/share/X11/xkb/symbols/capslockarrow



          default partial xkb_symbols "basic" 

          include "de(basic)"
          include "shift(both_capslock_cancel)"

          key <CAPS>
          type[Group1] = "TWO_LEVEL",
          symbols[Group1] = [ Down, NoSymbol ],
          actions[Group1] = [ NoAction(), RedirectKey(key=<UP>, clearmods=Shift) ]
          ;
          ;


          activate the new layout with



          setxkbmap capslockarrow


          Notes on the layout file



          • The new layout file derives from de(basic). That is the layout for the standard german keyboard. You can add any other layout here like us(basic) or us(euro). see /usr/share/X11/xkb/symbols/ to get a glance of what is possible. The two letter code is the filename and in brackets is the respective xkb_symbols definition from the file.


          • You would not have a caps key modifier anymore. Therefore I added a sort of replacement for Caps: shift(both_capslock_cancel) By pressing both LSHIFT and RSHIFT together, you can activate CAPS Lock and you release the Lock again with any other press of a Shift key.


          • If anyone is wondering why I did not use a new type definition for that: I simply could not release the Shift modifier before the action of the Up Key was triggered. Releasing the Shift key though should be possible by explicitly calling preserve[Shift] = None in a spearated xkb_types.


          • As stated in the comments below, Wayland will also rely on XKB but will not allow redirections.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 11 at 1:02

























          answered Feb 3 at 23:16









          ukos

          476114




          476114











          • wayland uses XKB (via xkbcommon, not the X11 library), so modified XKB options will work. (at least if they're placed in the system XKB files.) xmodmap will not function.
            – quixotic
            Feb 4 at 0:32










          • Thanks for the explanation. I figured I was sending shift + up. Now I can see I am when I highlight text in chrome. I guess the real question is how do I disable the level 2 switch, only for this scenario
            – Jared Beach
            Feb 4 at 4:40










          • I found the solution and updated my post.
            – ukos
            Feb 5 at 1:57










          • nice solution, thanks. i don't know if this will work in contexts like wayland that use xkbcommon -- redirect actions are listed among the current incompatibilities, though that could be remedied in the future.
            – quixotic
            Feb 6 at 8:50






          • 1




            @jared-beach done
            – ukos
            Feb 11 at 1:02
















          • wayland uses XKB (via xkbcommon, not the X11 library), so modified XKB options will work. (at least if they're placed in the system XKB files.) xmodmap will not function.
            – quixotic
            Feb 4 at 0:32










          • Thanks for the explanation. I figured I was sending shift + up. Now I can see I am when I highlight text in chrome. I guess the real question is how do I disable the level 2 switch, only for this scenario
            – Jared Beach
            Feb 4 at 4:40










          • I found the solution and updated my post.
            – ukos
            Feb 5 at 1:57










          • nice solution, thanks. i don't know if this will work in contexts like wayland that use xkbcommon -- redirect actions are listed among the current incompatibilities, though that could be remedied in the future.
            – quixotic
            Feb 6 at 8:50






          • 1




            @jared-beach done
            – ukos
            Feb 11 at 1:02















          wayland uses XKB (via xkbcommon, not the X11 library), so modified XKB options will work. (at least if they're placed in the system XKB files.) xmodmap will not function.
          – quixotic
          Feb 4 at 0:32




          wayland uses XKB (via xkbcommon, not the X11 library), so modified XKB options will work. (at least if they're placed in the system XKB files.) xmodmap will not function.
          – quixotic
          Feb 4 at 0:32












          Thanks for the explanation. I figured I was sending shift + up. Now I can see I am when I highlight text in chrome. I guess the real question is how do I disable the level 2 switch, only for this scenario
          – Jared Beach
          Feb 4 at 4:40




          Thanks for the explanation. I figured I was sending shift + up. Now I can see I am when I highlight text in chrome. I guess the real question is how do I disable the level 2 switch, only for this scenario
          – Jared Beach
          Feb 4 at 4:40












          I found the solution and updated my post.
          – ukos
          Feb 5 at 1:57




          I found the solution and updated my post.
          – ukos
          Feb 5 at 1:57












          nice solution, thanks. i don't know if this will work in contexts like wayland that use xkbcommon -- redirect actions are listed among the current incompatibilities, though that could be remedied in the future.
          – quixotic
          Feb 6 at 8:50




          nice solution, thanks. i don't know if this will work in contexts like wayland that use xkbcommon -- redirect actions are listed among the current incompatibilities, though that could be remedied in the future.
          – quixotic
          Feb 6 at 8:50




          1




          1




          @jared-beach done
          – ukos
          Feb 11 at 1:02




          @jared-beach done
          – ukos
          Feb 11 at 1:02

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1000594%2fhow-to-map-caps-lock-to-arrow-keys%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          GRUB: Fatal! inconsistent data read from (0x84) 0+xxxxxx

          `kcmshell` modules relation with `/usr/share/applications`

          How to enroll fingerprints to Ubuntu 17.10 with VFS491