How to bind mouse buttons to keys?
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
add a comment |
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
add a comment |
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
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
mouse scripts input-devices
asked Oct 23 '10 at 11:22
Callum RogersCallum Rogers
3402511
3402511
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
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
add a comment |
Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).
Open a terminal (like xterm/terminal/terminator), become root (
sudo su -
) or use sudo in front of the command:
apt install xbindkeys xautomation
Check the button mapping with
xev
, for this you don't need root permission so exit the root session (withexit
) or open another terminal as user.
xev | grep button
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.
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
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.
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
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,
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).
Open a terminal (like xterm/terminal/terminator), become root (
sudo su -
) or use sudo in front of the command:
apt install xbindkeys xautomation
Check the button mapping with
xev
, for this you don't need root permission so exit the root session (withexit
) or open another terminal as user.
xev | grep button
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.
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
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.
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
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,
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.
add a comment |
Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).
Open a terminal (like xterm/terminal/terminator), become root (
sudo su -
) or use sudo in front of the command:
apt install xbindkeys xautomation
Check the button mapping with
xev
, for this you don't need root permission so exit the root session (withexit
) or open another terminal as user.
xev | grep button
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.
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
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.
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
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,
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.
add a comment |
Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).
Open a terminal (like xterm/terminal/terminator), become root (
sudo su -
) or use sudo in front of the command:
apt install xbindkeys xautomation
Check the button mapping with
xev
, for this you don't need root permission so exit the root session (withexit
) or open another terminal as user.
xev | grep button
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.
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
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.
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
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,
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.
Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).
Open a terminal (like xterm/terminal/terminator), become root (
sudo su -
) or use sudo in front of the command:
apt install xbindkeys xautomation
Check the button mapping with
xev
, for this you don't need root permission so exit the root session (withexit
) or open another terminal as user.
xev | grep button
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.
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
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.
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
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,
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.
edited Dec 30 '18 at 7:08
karel
58.6k13128147
58.6k13128147
answered Dec 30 '18 at 3:30
malasamalasa
12
12
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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