{"id":84,"date":"2012-11-10T11:18:22","date_gmt":"2012-11-10T19:18:22","guid":{"rendered":"http:\/\/flenniken.net\/blog\/?p=84"},"modified":"2012-12-02T13:44:27","modified_gmt":"2012-12-02T21:44:27","slug":"xcape","status":"publish","type":"post","link":"https:\/\/flenniken.net\/blog\/xcape\/","title":{"rendered":"XCAPE"},"content":{"rendered":"<p>I&#8217;ve configured my keyboard to generate a special key code when you press the Caps Lock key by itself. I use this as a mode switch in Emacs which I have configured somewhat like VIM.<\/p>\n<p>For VIM users the escape key is used to switch between typing and command mode and escape is pressed all the time.<\/p>\n<p>The problem is that it is a long reach to hit the escape key. The Caps Lock key is in a prime location and who needs the Caps Lock key anyway? (You can move it if you want.)<\/p>\n<p>On Ubuntu I use the program xcape to accomplish this remapping. I will show you how to download, install, configure and test xcape.<\/p>\n<p><em>Note:<\/em><br \/>\n<em>On the Mac you can use KeyRemap4MacBook and PCKeyboardHack to do the same thing.<\/em><\/p>\n<p>Here is the link to xcape: <a title=\"https:\/\/github.com\/alols\/xcape#readme\" href=\"https:\/\/github.com\/alols\/xcape#readme\">https:\/\/github.com\/alols\/xcape#readme<\/a><\/p>\n<p>First install the necessary dependencies. It requires git, gcc, make libx11-dev and libxtst-dev libraries. Open a terminal and type:<\/p>\n<p><strong>sudo apt-get install git gcc make libx11-dev libxtst-dev<\/strong><\/p>\n<p>Next make a folder for xcape in your home folder:<\/p>\n<p><strong>cd<\/strong><br \/>\n<strong>mkdir xcape<\/strong><br \/>\n<strong>cd xcape<\/strong><\/p>\n<p>Download the source code for xcape:<\/p>\n<p><strong>git clone <a title=\"https:\/\/github.com\/alols\/xcape.git\" href=\"https:\/\/github.com\/alols\/xcape.git\">https:\/\/github.com\/alols\/xcape.git<\/a> .<\/strong><\/p>\n<p>Build the application. This makes a executable called xcape.<\/p>\n<p><strong>make<\/strong><\/p>\n<p><strong>ls<\/strong><br \/>\nLICENSE Makefile README.md xcape xcape.c<\/p>\n<p>To see the usage statement:<\/p>\n<p><strong>.\/xcape -h<\/strong><br \/>\n.\/xcape: invalid option &#8212; &#8216;h&#8217;<br \/>\nUsage: .\/xcape [-d] [-t timeout_ms] [-e &lt;mapping&gt;]<br \/>\nRuns as a daemon unless -d flag is set<\/p>\n<p>I am using the Ubuntu system settings to turn the Caps Lock into a control key and xcape to generate Alt+R when it (now a control key) is pressed by itself.<\/p>\n<p>Use the system settings to make Caps Lock a control key:<\/p>\n<ul>\n<li>Open system settings Keyboard Layout<\/li>\n<li>Click Options<\/li>\n<li>Click &#8220;Ctrl key position&#8221;<\/li>\n<li>Check &#8220;Caps Lock as Ctrl&#8221;<\/li>\n<li>Close the dialogs<\/li>\n<\/ul>\n<p>If you are a VIM user and you want Caps Lock by itself to generate an escape, use the defaults and run xcape like:<\/p>\n<p><strong>.\/xcape<\/strong><\/p>\n<p>I want the left control to generate Alt_L+R when pressed on its own, so I run xcape like:<\/p>\n<p><strong>.\/xcape -e &#8216;Control_L=Alt_L|R&#8217;<\/strong><\/p>\n<p>You can remap multiple keys at once using the semicolon to separate commands:<\/p>\n<p><strong>xcape -e &#8216;Shift_L=Escape;Control_L=Control_L|O&#8217;<\/strong><\/p>\n<p>The list of key names is found in the header file X11\/keysymdef.h (remove the XK_ prefix). Here is a link to the file:<\/p>\n<p><a title=\"keysymdef.h\" href=\"http:\/\/cgit.freedesktop.org\/xorg\/proto\/x11proto\/plain\/keysymdef.h\">http:\/\/cgit.freedesktop.org\/xorg\/proto\/x11proto\/plain\/keysymdef.h<\/a><\/p>\n<p>Run xev to test the keycodes generated when you type a key.<\/p>\n<p><strong>xev<\/strong><\/p>\n<p>For my case t<em>he system generates a Control_L press and release then the Alt_L+R press and release combination.<\/em><\/p>\n<p><em>Note:<\/em><br \/>\n<em>If you change the keyboard system settings, rerun xcape or it will continue to run with the old settings.<\/em><\/p>\n<p><em>Note:<\/em><br \/>\n<em>Make sure you only run one xcape process. To see the xcape process or processes:<\/em><\/p>\n<p><strong>ps aux | grep xcape<\/strong><br \/>\nsteve 13342 0.0 0.0 11984 688 ? Ssl 09:25 0:00 .\/xcape<br \/>\nsteve 13467 0.0 0.0 11984 684 ? Ssl 09:44 0:00 .\/xcape<br \/>\nsteve 13564 0.0 0.0 11984 688 ? Ssl 10:01 0:00 .\/xcape -e Control_L Alt_L R<\/p>\n<p>Quit the extra running xcape processes above:<\/p>\n<p><strong>kill 13342<\/strong><br \/>\n<strong>kill 13467<\/strong><\/p>\n<p>To make xcape run once when you login, add the xcape to your .bashrc file,<\/p>\n<p><strong>emacs ~\/.bashrc<\/strong><\/p>\n<p>add this line to the bottom of the file:<\/p>\n<p># Generate a Alt+R when the control key is pressed and released by itself.<br \/>\n# Run xcape once.<br \/>\nif [ -z $XCAPE ] ; then<br \/>\nexport XCAPE=1<br \/>\n~\/xcape\/xcape -e &#8216;Control_L=Alt_L|R&#8217;<br \/>\nfi<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve configured my keyboard to generate a special key code when you press the Caps Lock key by itself. I use this as a mode switch in Emacs which I have configured somewhat like VIM. For VIM users the escape &hellip; <a href=\"https:\/\/flenniken.net\/blog\/xcape\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,10,11],"tags":[],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-keyboard","category-linux","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":6,"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":88,"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/posts\/84\/revisions\/88"}],"wp:attachment":[{"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flenniken.net\/blog\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}