How to bind mouse buttons to keys?












17















I have a Logitech MX400 Laser Mouse which has 5 buttons + 4 for vertical/horizontal scrolling. I would like it set up so instead of horizontal scrolling pressing right on the scrollwheel will send Ctrl+Tab and left will send Ctrl+Shift+Tab, which will allow me to cycle through tabs in browsers.



Also, it would be nice if I could remap the middle button to one of the ones on the side as it is really hard to press down.



Another bonus would be if I could write a script that allows me to define what buttons do what dependent on which window is currently active.



I have tried using xmodmap but I could only see how to rearrange buttons, not have them send key signals.



Thanks in advance.





Button Map (using xev):



Left        1
Middle 2
Right 3
ScrollUp 4
ScrollDown 5
ScrollLeft 6
ScrollRight 7
Backward 8
Forward 9









share|improve this question



























    17















    I have a Logitech MX400 Laser Mouse which has 5 buttons + 4 for vertical/horizontal scrolling. I would like it set up so instead of horizontal scrolling pressing right on the scrollwheel will send Ctrl+Tab and left will send Ctrl+Shift+Tab, which will allow me to cycle through tabs in browsers.



    Also, it would be nice if I could remap the middle button to one of the ones on the side as it is really hard to press down.



    Another bonus would be if I could write a script that allows me to define what buttons do what dependent on which window is currently active.



    I have tried using xmodmap but I could only see how to rearrange buttons, not have them send key signals.



    Thanks in advance.





    Button Map (using xev):



    Left        1
    Middle 2
    Right 3
    ScrollUp 4
    ScrollDown 5
    ScrollLeft 6
    ScrollRight 7
    Backward 8
    Forward 9









    share|improve this question

























      17












      17








      17


      8






      I have a Logitech MX400 Laser Mouse which has 5 buttons + 4 for vertical/horizontal scrolling. I would like it set up so instead of horizontal scrolling pressing right on the scrollwheel will send Ctrl+Tab and left will send Ctrl+Shift+Tab, which will allow me to cycle through tabs in browsers.



      Also, it would be nice if I could remap the middle button to one of the ones on the side as it is really hard to press down.



      Another bonus would be if I could write a script that allows me to define what buttons do what dependent on which window is currently active.



      I have tried using xmodmap but I could only see how to rearrange buttons, not have them send key signals.



      Thanks in advance.





      Button Map (using xev):



      Left        1
      Middle 2
      Right 3
      ScrollUp 4
      ScrollDown 5
      ScrollLeft 6
      ScrollRight 7
      Backward 8
      Forward 9









      share|improve this question














      I have a Logitech MX400 Laser Mouse which has 5 buttons + 4 for vertical/horizontal scrolling. I would like it set up so instead of horizontal scrolling pressing right on the scrollwheel will send Ctrl+Tab and left will send Ctrl+Shift+Tab, which will allow me to cycle through tabs in browsers.



      Also, it would be nice if I could remap the middle button to one of the ones on the side as it is really hard to press down.



      Another bonus would be if I could write a script that allows me to define what buttons do what dependent on which window is currently active.



      I have tried using xmodmap but I could only see how to rearrange buttons, not have them send key signals.



      Thanks in advance.





      Button Map (using xev):



      Left        1
      Middle 2
      Right 3
      ScrollUp 4
      ScrollDown 5
      ScrollLeft 6
      ScrollRight 7
      Backward 8
      Forward 9






      mouse scripts input-devices






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 23 '10 at 11:22









      Callum RogersCallum Rogers

      3402511




      3402511






















          2 Answers
          2






          active

          oldest

          votes


















          16














          The xbindkeys and xte can help you.



          For example my .xbindkeysrc file looks like this:



          # close the window under the mouse cursor
          "xte 'mouseclick 1' && xte 'keydown Alt_L' 'key F4' 'keyup Alt_L'"
          b:8+Release

          # double click
          "xte 'mouseclick 1' 'mouseclick 1'"
          b:9





          share|improve this answer


























          • This is fantastic and extensible, many many thanks

            – Callum Rogers
            Oct 23 '10 at 14:11






          • 1





            To get xte on Ubuntu 16.x, you'll have to install xautomation from apt.

            – 1111161171159459134
            Dec 26 '16 at 15:09













          • That doesn't work as well as I like, because it doesn't work the same if I hold the button down. My old mouse had a button that enables the scroll wheel to spin freely, which is great if I just want to start it moving real fast and scroll a long way. But my new one doesn't have that, so I bound two buttons on the side (I think they're designed as back/forward buttons for Web browsing) to the PgUp/PgDn keys. But I have to press them repeatedly if I want to keep scrolling; I can't just hold them down. How do I make it hold the key as long as I hold the button?

            – flarn2006
            Dec 28 '16 at 1:52





















          0














          Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).





          1. Open a terminal (like xterm/terminal/terminator), become root (sudo su -) or use sudo in front of the command:



            apt install xbindkeys xautomation



          2. Check the button mapping with xev, for this you don't need root permission so exit the root session (with exit) or open another terminal as user.



            xev | grep button



          3. A small window will appear. You have to move the mouse into that window and press the button you want to remap. An example output in the terminal will be:



            state 0x0, button 8, same_screen YES


            This is the 2nd side button on my mouse which I want to use as PAGE_DOWN.



            state 0x0, button 9, same_screen YES


            This is the 1st (yes, the order is reversed) side button I want to use as PAGE_UP.




          4. When you have all buttons you want to remap you can close the small xev window. Open your favorite editor (gedit/vi/nano for example) and edit the configuration file.



            vi .xbindkeysrc



          5. If you already have some content in the file, look if there is already a binding like it (unlikely, not by default) and add at the end.



            #Pagedown press
            "xte 'keydown Next'"
            b:8

            #Pagedown release
            "xte 'keyup Next'"
            b:8 + Release

            #Pagedup press
            "xte 'keydown Prior'"
            b:9

            #Pageup release
            "xte 'keyup Prior'"
            b:9 + Release


            Note: you need two entries, one for the button press and one for the release.




          6. The buttons 8+9 will be mapped to the keys "Next" (which is PAGE_DOWN) and "Prior" (PAGE_UP). If you want to map different keys you can find the keysymbol with xev.



            xev | grep keysym



          7. Like before, start it in a terminal, move the mouse to the small window and press the wanted key.



            state 0x0, keycode 117 (keysym 0xff56, Next), same_screen YES,



          8. Save and kill xbindings.



            killall xbindkeys ; xbindkeys



          You can now use the additional side buttons on the mouse. The setting will be loaded automatically on next reboot/login. You only need the killall [...] command from above if you change the settings.






          share|improve this answer

























            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            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%2f9048%2fhow-to-bind-mouse-buttons-to-keys%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            16














            The xbindkeys and xte can help you.



            For example my .xbindkeysrc file looks like this:



            # close the window under the mouse cursor
            "xte 'mouseclick 1' && xte 'keydown Alt_L' 'key F4' 'keyup Alt_L'"
            b:8+Release

            # double click
            "xte 'mouseclick 1' 'mouseclick 1'"
            b:9





            share|improve this answer


























            • This is fantastic and extensible, many many thanks

              – Callum Rogers
              Oct 23 '10 at 14:11






            • 1





              To get xte on Ubuntu 16.x, you'll have to install xautomation from apt.

              – 1111161171159459134
              Dec 26 '16 at 15:09













            • That doesn't work as well as I like, because it doesn't work the same if I hold the button down. My old mouse had a button that enables the scroll wheel to spin freely, which is great if I just want to start it moving real fast and scroll a long way. But my new one doesn't have that, so I bound two buttons on the side (I think they're designed as back/forward buttons for Web browsing) to the PgUp/PgDn keys. But I have to press them repeatedly if I want to keep scrolling; I can't just hold them down. How do I make it hold the key as long as I hold the button?

              – flarn2006
              Dec 28 '16 at 1:52


















            16














            The xbindkeys and xte can help you.



            For example my .xbindkeysrc file looks like this:



            # close the window under the mouse cursor
            "xte 'mouseclick 1' && xte 'keydown Alt_L' 'key F4' 'keyup Alt_L'"
            b:8+Release

            # double click
            "xte 'mouseclick 1' 'mouseclick 1'"
            b:9





            share|improve this answer


























            • This is fantastic and extensible, many many thanks

              – Callum Rogers
              Oct 23 '10 at 14:11






            • 1





              To get xte on Ubuntu 16.x, you'll have to install xautomation from apt.

              – 1111161171159459134
              Dec 26 '16 at 15:09













            • That doesn't work as well as I like, because it doesn't work the same if I hold the button down. My old mouse had a button that enables the scroll wheel to spin freely, which is great if I just want to start it moving real fast and scroll a long way. But my new one doesn't have that, so I bound two buttons on the side (I think they're designed as back/forward buttons for Web browsing) to the PgUp/PgDn keys. But I have to press them repeatedly if I want to keep scrolling; I can't just hold them down. How do I make it hold the key as long as I hold the button?

              – flarn2006
              Dec 28 '16 at 1:52
















            16












            16








            16







            The xbindkeys and xte can help you.



            For example my .xbindkeysrc file looks like this:



            # close the window under the mouse cursor
            "xte 'mouseclick 1' && xte 'keydown Alt_L' 'key F4' 'keyup Alt_L'"
            b:8+Release

            # double click
            "xte 'mouseclick 1' 'mouseclick 1'"
            b:9





            share|improve this answer















            The xbindkeys and xte can help you.



            For example my .xbindkeysrc file looks like this:



            # close the window under the mouse cursor
            "xte 'mouseclick 1' && xte 'keydown Alt_L' 'key F4' 'keyup Alt_L'"
            b:8+Release

            # double click
            "xte 'mouseclick 1' 'mouseclick 1'"
            b:9






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 28 '12 at 19:31









            diedthreetimes

            10316




            10316










            answered Oct 23 '10 at 13:44









            lukaszlukasz

            1,74621725




            1,74621725













            • This is fantastic and extensible, many many thanks

              – Callum Rogers
              Oct 23 '10 at 14:11






            • 1





              To get xte on Ubuntu 16.x, you'll have to install xautomation from apt.

              – 1111161171159459134
              Dec 26 '16 at 15:09













            • That doesn't work as well as I like, because it doesn't work the same if I hold the button down. My old mouse had a button that enables the scroll wheel to spin freely, which is great if I just want to start it moving real fast and scroll a long way. But my new one doesn't have that, so I bound two buttons on the side (I think they're designed as back/forward buttons for Web browsing) to the PgUp/PgDn keys. But I have to press them repeatedly if I want to keep scrolling; I can't just hold them down. How do I make it hold the key as long as I hold the button?

              – flarn2006
              Dec 28 '16 at 1:52





















            • This is fantastic and extensible, many many thanks

              – Callum Rogers
              Oct 23 '10 at 14:11






            • 1





              To get xte on Ubuntu 16.x, you'll have to install xautomation from apt.

              – 1111161171159459134
              Dec 26 '16 at 15:09













            • That doesn't work as well as I like, because it doesn't work the same if I hold the button down. My old mouse had a button that enables the scroll wheel to spin freely, which is great if I just want to start it moving real fast and scroll a long way. But my new one doesn't have that, so I bound two buttons on the side (I think they're designed as back/forward buttons for Web browsing) to the PgUp/PgDn keys. But I have to press them repeatedly if I want to keep scrolling; I can't just hold them down. How do I make it hold the key as long as I hold the button?

              – flarn2006
              Dec 28 '16 at 1:52



















            This is fantastic and extensible, many many thanks

            – Callum Rogers
            Oct 23 '10 at 14:11





            This is fantastic and extensible, many many thanks

            – Callum Rogers
            Oct 23 '10 at 14:11




            1




            1





            To get xte on Ubuntu 16.x, you'll have to install xautomation from apt.

            – 1111161171159459134
            Dec 26 '16 at 15:09







            To get xte on Ubuntu 16.x, you'll have to install xautomation from apt.

            – 1111161171159459134
            Dec 26 '16 at 15:09















            That doesn't work as well as I like, because it doesn't work the same if I hold the button down. My old mouse had a button that enables the scroll wheel to spin freely, which is great if I just want to start it moving real fast and scroll a long way. But my new one doesn't have that, so I bound two buttons on the side (I think they're designed as back/forward buttons for Web browsing) to the PgUp/PgDn keys. But I have to press them repeatedly if I want to keep scrolling; I can't just hold them down. How do I make it hold the key as long as I hold the button?

            – flarn2006
            Dec 28 '16 at 1:52







            That doesn't work as well as I like, because it doesn't work the same if I hold the button down. My old mouse had a button that enables the scroll wheel to spin freely, which is great if I just want to start it moving real fast and scroll a long way. But my new one doesn't have that, so I bound two buttons on the side (I think they're designed as back/forward buttons for Web browsing) to the PgUp/PgDn keys. But I have to press them repeatedly if I want to keep scrolling; I can't just hold them down. How do I make it hold the key as long as I hold the button?

            – flarn2006
            Dec 28 '16 at 1:52















            0














            Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).





            1. Open a terminal (like xterm/terminal/terminator), become root (sudo su -) or use sudo in front of the command:



              apt install xbindkeys xautomation



            2. Check the button mapping with xev, for this you don't need root permission so exit the root session (with exit) or open another terminal as user.



              xev | grep button



            3. A small window will appear. You have to move the mouse into that window and press the button you want to remap. An example output in the terminal will be:



              state 0x0, button 8, same_screen YES


              This is the 2nd side button on my mouse which I want to use as PAGE_DOWN.



              state 0x0, button 9, same_screen YES


              This is the 1st (yes, the order is reversed) side button I want to use as PAGE_UP.




            4. When you have all buttons you want to remap you can close the small xev window. Open your favorite editor (gedit/vi/nano for example) and edit the configuration file.



              vi .xbindkeysrc



            5. If you already have some content in the file, look if there is already a binding like it (unlikely, not by default) and add at the end.



              #Pagedown press
              "xte 'keydown Next'"
              b:8

              #Pagedown release
              "xte 'keyup Next'"
              b:8 + Release

              #Pagedup press
              "xte 'keydown Prior'"
              b:9

              #Pageup release
              "xte 'keyup Prior'"
              b:9 + Release


              Note: you need two entries, one for the button press and one for the release.




            6. The buttons 8+9 will be mapped to the keys "Next" (which is PAGE_DOWN) and "Prior" (PAGE_UP). If you want to map different keys you can find the keysymbol with xev.



              xev | grep keysym



            7. Like before, start it in a terminal, move the mouse to the small window and press the wanted key.



              state 0x0, keycode 117 (keysym 0xff56, Next), same_screen YES,



            8. Save and kill xbindings.



              killall xbindkeys ; xbindkeys



            You can now use the additional side buttons on the mouse. The setting will be loaded automatically on next reboot/login. You only need the killall [...] command from above if you change the settings.






            share|improve this answer






























              0














              Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).





              1. Open a terminal (like xterm/terminal/terminator), become root (sudo su -) or use sudo in front of the command:



                apt install xbindkeys xautomation



              2. Check the button mapping with xev, for this you don't need root permission so exit the root session (with exit) or open another terminal as user.



                xev | grep button



              3. A small window will appear. You have to move the mouse into that window and press the button you want to remap. An example output in the terminal will be:



                state 0x0, button 8, same_screen YES


                This is the 2nd side button on my mouse which I want to use as PAGE_DOWN.



                state 0x0, button 9, same_screen YES


                This is the 1st (yes, the order is reversed) side button I want to use as PAGE_UP.




              4. When you have all buttons you want to remap you can close the small xev window. Open your favorite editor (gedit/vi/nano for example) and edit the configuration file.



                vi .xbindkeysrc



              5. If you already have some content in the file, look if there is already a binding like it (unlikely, not by default) and add at the end.



                #Pagedown press
                "xte 'keydown Next'"
                b:8

                #Pagedown release
                "xte 'keyup Next'"
                b:8 + Release

                #Pagedup press
                "xte 'keydown Prior'"
                b:9

                #Pageup release
                "xte 'keyup Prior'"
                b:9 + Release


                Note: you need two entries, one for the button press and one for the release.




              6. The buttons 8+9 will be mapped to the keys "Next" (which is PAGE_DOWN) and "Prior" (PAGE_UP). If you want to map different keys you can find the keysymbol with xev.



                xev | grep keysym



              7. Like before, start it in a terminal, move the mouse to the small window and press the wanted key.



                state 0x0, keycode 117 (keysym 0xff56, Next), same_screen YES,



              8. Save and kill xbindings.



                killall xbindkeys ; xbindkeys



              You can now use the additional side buttons on the mouse. The setting will be loaded automatically on next reboot/login. You only need the killall [...] command from above if you change the settings.






              share|improve this answer




























                0












                0








                0







                Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).





                1. Open a terminal (like xterm/terminal/terminator), become root (sudo su -) or use sudo in front of the command:



                  apt install xbindkeys xautomation



                2. Check the button mapping with xev, for this you don't need root permission so exit the root session (with exit) or open another terminal as user.



                  xev | grep button



                3. A small window will appear. You have to move the mouse into that window and press the button you want to remap. An example output in the terminal will be:



                  state 0x0, button 8, same_screen YES


                  This is the 2nd side button on my mouse which I want to use as PAGE_DOWN.



                  state 0x0, button 9, same_screen YES


                  This is the 1st (yes, the order is reversed) side button I want to use as PAGE_UP.




                4. When you have all buttons you want to remap you can close the small xev window. Open your favorite editor (gedit/vi/nano for example) and edit the configuration file.



                  vi .xbindkeysrc



                5. If you already have some content in the file, look if there is already a binding like it (unlikely, not by default) and add at the end.



                  #Pagedown press
                  "xte 'keydown Next'"
                  b:8

                  #Pagedown release
                  "xte 'keyup Next'"
                  b:8 + Release

                  #Pagedup press
                  "xte 'keydown Prior'"
                  b:9

                  #Pageup release
                  "xte 'keyup Prior'"
                  b:9 + Release


                  Note: you need two entries, one for the button press and one for the release.




                6. The buttons 8+9 will be mapped to the keys "Next" (which is PAGE_DOWN) and "Prior" (PAGE_UP). If you want to map different keys you can find the keysymbol with xev.



                  xev | grep keysym



                7. Like before, start it in a terminal, move the mouse to the small window and press the wanted key.



                  state 0x0, keycode 117 (keysym 0xff56, Next), same_screen YES,



                8. Save and kill xbindings.



                  killall xbindkeys ; xbindkeys



                You can now use the additional side buttons on the mouse. The setting will be loaded automatically on next reboot/login. You only need the killall [...] command from above if you change the settings.






                share|improve this answer















                Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).





                1. Open a terminal (like xterm/terminal/terminator), become root (sudo su -) or use sudo in front of the command:



                  apt install xbindkeys xautomation



                2. Check the button mapping with xev, for this you don't need root permission so exit the root session (with exit) or open another terminal as user.



                  xev | grep button



                3. A small window will appear. You have to move the mouse into that window and press the button you want to remap. An example output in the terminal will be:



                  state 0x0, button 8, same_screen YES


                  This is the 2nd side button on my mouse which I want to use as PAGE_DOWN.



                  state 0x0, button 9, same_screen YES


                  This is the 1st (yes, the order is reversed) side button I want to use as PAGE_UP.




                4. When you have all buttons you want to remap you can close the small xev window. Open your favorite editor (gedit/vi/nano for example) and edit the configuration file.



                  vi .xbindkeysrc



                5. If you already have some content in the file, look if there is already a binding like it (unlikely, not by default) and add at the end.



                  #Pagedown press
                  "xte 'keydown Next'"
                  b:8

                  #Pagedown release
                  "xte 'keyup Next'"
                  b:8 + Release

                  #Pagedup press
                  "xte 'keydown Prior'"
                  b:9

                  #Pageup release
                  "xte 'keyup Prior'"
                  b:9 + Release


                  Note: you need two entries, one for the button press and one for the release.




                6. The buttons 8+9 will be mapped to the keys "Next" (which is PAGE_DOWN) and "Prior" (PAGE_UP). If you want to map different keys you can find the keysymbol with xev.



                  xev | grep keysym



                7. Like before, start it in a terminal, move the mouse to the small window and press the wanted key.



                  state 0x0, keycode 117 (keysym 0xff56, Next), same_screen YES,



                8. Save and kill xbindings.



                  killall xbindkeys ; xbindkeys



                You can now use the additional side buttons on the mouse. The setting will be loaded automatically on next reboot/login. You only need the killall [...] command from above if you change the settings.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 30 '18 at 7:08









                karel

                58.6k13128147




                58.6k13128147










                answered Dec 30 '18 at 3:30









                malasamalasa

                12




                12






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f9048%2fhow-to-bind-mouse-buttons-to-keys%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                    ComboBox Display Member on multiple fields

                    Is it possible to collect Nectar points via Trainline?