{"id":1012,"date":"2018-06-27T17:03:51","date_gmt":"2018-06-27T17:03:51","guid":{"rendered":"http:\/\/mclements.net\/blogWP\/?p=1012"},"modified":"2018-06-27T18:45:14","modified_gmt":"2018-06-27T18:45:14","slug":"cool-mouse-stuff-with-linux","status":"publish","type":"post","link":"http:\/\/mclements.net\/blogWP\/index.php\/2018\/06\/27\/cool-mouse-stuff-with-linux\/","title":{"rendered":"Cool Mouse Stuff with Linux"},"content":{"rendered":"<p>Linux has built-in tools for programming the buttons on your mouse or trackball. You don&#8217;t need any drivers or proprietary software. Just a few simple tools you can install from the repos. I&#8217;m doing this on Ubuntu 16 and 18, but it should work on any recent Linux distro.<\/p>\n<p>First, use <strong>xev<\/strong> to detect how your system is recognizing the mouse buttons. Start <strong>xev<\/strong> from a command prompt, then hover over its window, click each button, and look at the text in the command prompt window. This will tell you the # for each button. The first 3 buttons are always defined the same way: left-click is button 1, middle-click 2, right-click 3. Extra buttons are &#8220;non-standard&#8221; and can be defined in any way.<\/p>\n<p>To change what a button does, use <strong>xbindkeys<\/strong>. Its control script is a file in your home directory called <strong>.xbindkeysrc<\/strong>. The app <strong>xte<\/strong> fabricates keystrokes and mouseclicks.<\/p>\n<p>For example: here&#8217;s an .xbindkeysrc that does 2 things:<\/p>\n<ul>\n<li>Single click of button 2 (middle button) causes double-click of button 1 (left)<\/li>\n<li>Single click of button 9 causes Control-click of button 1.<\/li>\n<\/ul>\n<pre># button 2 (scroll wheel) is double click\r\n\"\/usr\/bin\/xte 'mouseclick 1' 'mouseclick 1'\"\r\nb:2 + release\r\n\r\n# button 9 (upper left alternate) is control + left click\r\n\"\/usr\/bin\/xte 'keydown Control_L' 'mouseclick 1' 'keyup Control_L'\"\r\nb:9 + release<\/pre>\n<p>This should work everywhere in all apps. It does work in some apps (like Thunar), but not in others (like Firefox). I wondered &#8211; why?<\/p>\n<p><strong>Limitation 1<br \/>\n<\/strong><\/p>\n<p>After experimenting, I discovered that <strong>xte<\/strong> is too fast for some apps. I added a few strategically located brief (10 ms) delays and it worked everywhere.<\/p>\n<p>Example: change the above to this:<\/p>\n<pre># button 2 (scroll wheel) is double click\r\n\"\/usr\/bin\/xte 'mouseclick 1' 'usleep 10000' 'mouseclick 1'\"\r\nb:2 + release\r\n\r\n# button 9 (upper left alternate) is control + left click\r\n\"\/usr\/bin\/xte 'keydown Control_L' 'mousedown 1' 'usleep 10000' 'mouseup 1' 'keyup Control_L'\"\r\nb:9 + release<\/pre>\n<p>The <strong>usleep<\/strong> param is in microseconds, so 10,000 is 10 milliseconds. This now works in all apps.<\/p>\n<p><strong>Limitation 2<br \/>\n<\/strong><\/p>\n<p>Another limitation: it&#8217;s hard to make the same button duplicate itself from xbindkeys. If you do this, it can lead to infinite loops. For example: xbindkeys can easily make a single click of button 2, cause a double-click of button 1. But xbindkeys can&#8217;t make a single click of button 1, cause a double-click of <em>the same button<\/em>. This will fail or cause an infinite loop.<\/p>\n<p>For that, use <strong>imwheel<\/strong>. Originally intended to adjust the sensitivity of the scroll wheel, it is also useful for other things. This is because internally, a scroll wheel is just 2 buttons: up and down. To make it more sensitive, imwheel duplicates each click of those buttons. But imwheel can do this with <em>any<\/em> buttons, not just the scroll wheel. Its config file is <strong>.imwheelrc<\/strong>, in your home directory.<\/p>\n<p>Here&#8217;s an imwheel config that doubles the scroll wheel sensitivity:<\/p>\n<pre># Apply to all apps (individual apps can be customized)\r\n\".*\"\r\n# Amplify scroll up\/down\r\nNone,\u00a0\u00a0 \u00a0Up,\u00a0\u00a0 \u00a0Button4,\u00a0\u00a0 \u00a02\r\nNone,\u00a0\u00a0 \u00a0Down,\u00a0\u00a0 \u00a0Button5,\u00a0\u00a0 \u00a02\r\n# Amplify scroll left\/right\r\nNone,\u00a0\u00a0 \u00a0Left,\u00a0\u00a0 \u00a0Button6,\u00a0\u00a0 \u00a010\r\nNone,\u00a0\u00a0 \u00a0Right,\u00a0\u00a0 \u00a0Button7,\u00a0\u00a0 \u00a010<\/pre>\n<p>On my trackball, the scroll wheel is Button 4 and Button 5. The scroll wheel tilts L and R; these are buttons 6 and 7. Yours may be different; check it with xev.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux has built-in tools for programming the buttons on your mouse or trackball. You don&#8217;t need any drivers or proprietary software. Just a few simple tools you can install from the repos. I&#8217;m doing this on Ubuntu 16 and 18, but it should work on any recent Linux distro. First, use xev to detect how &hellip; <a href=\"http:\/\/mclements.net\/blogWP\/index.php\/2018\/06\/27\/cool-mouse-stuff-with-linux\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Cool Mouse Stuff with Linux<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1012","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/posts\/1012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/comments?post=1012"}],"version-history":[{"count":4,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/posts\/1012\/revisions"}],"predecessor-version":[{"id":1016,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/posts\/1012\/revisions\/1016"}],"wp:attachment":[{"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/media?parent=1012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/categories?post=1012"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/tags?post=1012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}