Announcement

Collapse
No announcement yet.

How to modify keymap?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to modify keymap?

    I have a thinkpad x260 which does not have a context menu key. I'd like to remap the Alt_R key to the Menu key.

    I have found some tutorials like this one on how to use xmodmap to remap keys. But had no success with it.

    What is the most efficient way to do remap the keys?

    #2
    Have you looked in system settings->hardware, keyboard->advanced tab->Alt/Win key behaviour?
    Regards, John Little

    Comment


      #3
      Are you referring to the third key to the right of the spacebar in this image?
      Kubuntu 20.04

      Comment


        #4
        Originally posted by jlittle View Post
        Have you looked in system settings->hardware, keyboard->advanced tab->Alt/Win key behaviour?
        Thanks! I was able to map the Menu to the CapsLock, which isn't exactly what I want. But I can work with it.

        Comment


          #5
          Originally posted by chimak111 View Post
          Are you referring to the third key to the right of the spacebar in this image?
          That's the one.

          Comment


            #6
            Originally posted by TwoFistedJustice View Post
            What is the most efficient way to do remap the keys?
            If "efficiency" is your goal then the answer will depend on your system and how you use it.

            Multi-user or single user? If multi-user do you want all users to have the mod or just your user?

            For a single user, you can remap the keyboard with a keymap file or remap keys using xmodmap. Xmodmap is by far the simplest, but it's deprecated (may not be there forever into the future and gets no love from the devs). I use it to swap two keys on my keyboard to make my life easier (tilde/grave and bar/backslash).

            **Using Xmodmap**

            The two keycodes in question are:
            keycode 108 = Alt_R Meta_R Alt_R Meta_R
            keycode 135 = Menu NoSymbol Menu


            You have no menu so you need to remap the the Menu function to the Alt_R key. For format of the xmodmap file is:

            keycode <keycode> = <1st level> <Shift+1st> <2nd level> <shift+2nd> <3rd level> <shift+3rd level> <4th level> <shift+4th> ...

            Default 2nd level is CTRL.

            Supposedly, you can use eight modifiers, but xmodmap gets erratic above four. Anyway...


            I think if you simply remap keycode 108, you'll have what you want.

            If you use this entry: keycode 108 = Menu Meta_R Alt_R Meta_R

            then the un-shifted use of Alt_R should generate a Menu entry. Using CTRL+ALT_R and would still get you Alt_R. To break it all the way down:

            ALT_R = Menu
            Shift+ALT_R = Meta_R
            CTRL+ALT_R = ALT_R
            Shift+CRTL_ALT_R = Meta_R

            If you used: keycode 108 = Menu Alt_R Meta_R Alt_R, then you'd have

            ALT_R = Menu
            CTRL+ALT_R = ALT_R
            Shift+CRTL_ALT_R = Meta_R
            CTRL+ALT_R = ALT_R

            so that's the simplest and most efficient way for a single user.

            Please Read Me

            Comment


              #7
              ** Using a Keymap**
              First you have to make a loadkeys user accessible. I added a file to /etc/sudoers.d called "loadkeys" containing:

              stuart office.smith.lan = (root) NOPASSWD: /bin/loadkeys

              This allows my user to use loadkeys without a root password or sudo. Then in .profile I added this statement:

              sudo loadkeys ~/.stuart.kmap

              This loads the modified keymap when I log in. The keymap is much more expansive than Xmodmap. There's dozens of entries for each keycode with all the potential modifiers.

              Please Read Me

              Comment


                #8
                Originally posted by oshunluvr View Post
                ** Using a Keymap**
                First you have to make a loadkeys user accessible. I added a file to /etc/sudoers.d called "loadkeys" containing:

                stuart office.smith.lan = (root) NOPASSWD: /bin/loadkeys

                This allows my user to use loadkeys without a root password or sudo. Then in .profile I added this statement:

                sudo loadkeys ~/.stuart.kmap

                This loads the modified keymap when I log in. The keymap is much more expansive than Xmodmap. There's dozens of entries for each keycode with all the potential modifiers.
                This seems like the way to go since xmodmap has been declared programma-non-grata.

                It also seems potentially complex or complicated...

                What does "stuart office.smith.lan" represent? I'm guessing this would be different on my system...

                And can you point me to something that will fill me in on what changing the keymap entails?
                Is it as simple as listing the changes I want? Or would I have to create a whole keymap?

                Comment


                  #9
                  What does "stuart office.smith.lan" represent? I'm guessing this would be different on my system...
                  This is my entry in /etc/sudoers.d/ that lets my user run loadkeys without having to enter the root password. I use both xmodmap and loadkeys because xmodmap doesn't modify the keyboard in virtual terminals. Here's a short guide (more like hints):

                  https://superuser.com/questions/2901...eymap-in-linux

                  What I did was to dump my keymap using dumpkeys and save it. Then swapped the keys I wanted (bar/backslash and grave/tilde). However I believe in your case you will have to use xmodmap because the menu key isn't a console key.

                  Really, the "proper" and probably most efficient way is to use System Settings. Open "Input Devices > Keyboard > Ctrl Position" and notice that just past halfway down there is "Right Ctrl as Right Alt" the bottom option is "Swap Right Win with Right Alt". Some combination of those might get you what you want. In the section above that one - "Caps lock behavior" - you can set caps lock as Menu key also. I just found under Alt/Win behavior" there is an option "Alt is swapped with Win".

                  One of those or others yet discovered should get you where you want.

                  Please Read Me

                  Comment


                    #10
                    Originally posted by TwoFistedJustice View Post
                    What does "stuart office.smith.lan" represent?
                    "stuart" is his user name, and "office.smith.lan" is the hostname.

                    If there's only one user, on only one system, you could use
                    Code:
                    ALL    ALL=(ALL) NOPASSWD:/usr/bin/loadkeys
                    this lets anyone, on any system, as anyone, run /usr/bin/loadkeys without entering a password. (You still need to use "sudo"). Being permissive like this lets you copy it to another system and work there. For something like loadkeys one might find this acceptable. I worry about "nobody" and "guest" so I use my user name as the first word.
                    If there's several users, with several systems sharing one configuration, or you're paranoid, maybe
                    Code:
                    alice   langley=(bob) NOPASSWD:/usr/bin/loadkeys
                    would let alice, on lengley, run as bob, /usr/bin/loadkeys without a password. (Of course, unless bob is an alias for root it won't work, this is just an example.)

                    For editing sudoers files using visudo is "recommended", to avoid disabling a system entirely with a mistake, but if you're not familiar with vi IMO don't. For small one item files in /etc/sudoers.d I don't imagine you could cause too much trouble.
                    Regards, John Little

                    Comment

                    Working...
                    X