<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Random Wisdom &#187; keybindings</title>
	<atom:link href="http://scrolls.mafgani.net/tag/keybindings/feed/" rel="self" type="application/rss+xml" />
	<link>http://scrolls.mafgani.net</link>
	<description>An attempt at organizing my thoughts ...</description>
	<lastBuildDate>Sun, 13 Mar 2011 22:54:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Custom Keybinding (GNOME)</title>
		<link>http://scrolls.mafgani.net/2005/08/custom-keybinding-gnome/</link>
		<comments>http://scrolls.mafgani.net/2005/08/custom-keybinding-gnome/#comments</comments>
		<pubDate>Thu, 25 Aug 2005 07:42:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[How To ...]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[keybindings]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[keycodes]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=14</guid>
		<description><![CDATA[This is useful for multimedia keyboards that aren&#8217;t automatically recognized. Also useful when you want actions other that those offered in &#8220;gnome-keybinding-properties&#8220;. The first step is to check if the buttons are recognized at all. This can be accomplised by running &#8220;xev&#8221; $ xev Once the little window pops up, press any of the buttons [...]]]></description>
			<content:encoded><![CDATA[<p>This is useful for multimedia keyboards that aren&#8217;t automatically recognized. Also useful when you want actions other that those offered in &#8220;<span style="font-weight: bold;">gnome-keybinding-properties</span>&#8220;. The first step is to check if the buttons are recognized at all. This can be accomplised by running &#8220;<span style="font-weight: bold;">xev</span>&#8221;</p>
<pre>$ xev</pre>
<p>Once the little window pops up, press any of the buttons and see if you get an output like the following:</p>
<pre>
KeyPress event, serial 29, synthetic NO, window 0x3c00001,
root 0xd6, subw 0x0, time 2073408, (1033,644), root:(1051,745),
state 0x0, keycode 231 (keysym 0x0, NoSymbol), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyRelease event, serial 29, synthetic NO, window 0x3c00001,
root 0xd6, subw 0x0, time 2073529, (1033,644), root:(1051,745),
state 0x0, keycode 231 (keysym 0x0, NoSymbol), same_screen YES,
XLookupString gives 0 bytes:
</pre>
<p>If you do get the output, the important thing to note is the keycode (<span style="font-weight: bold;">keycode 231</span> here). Once you have the keycode for a key, you need to define a Key Symbol for it. To do this, you need a <span style="font-weight: bold;">xmodmap</span> file. You can get a copy of it using:</p>
<pre>
$ xmodmap -pke > ~/.xmodmaprc
</pre>
<p>Once the current map is dumped, open the file for editing and locate the required keycode:</p>
<pre>
$ vi ~/.xmodmaprc
[snip]
keycode 231 =
[snip]
</pre>
<p>As we can see there is no symbol associated with the keycode 231 yet. To get a list of available symbols, look at <span style="font-weight: bold;">/usr/X11R6/lib/X11/XKeysymDB</span>. Since the button is marked as Refresh, we can use XF86Refresh as a suitable symbol:</p>
<pre>
[snip]
keycode 231 = XF86Refresh
[snip]
</pre>
<p>Once all the required keys have been set, save the file.</p>
<p>To make the new map take effect (in GNOME):</p>
<pre>
$ gconftool-2 --set "/desktop/gnome/peripherals/keyboard/general/known_file_list"
  --type list --list-type string "[.xmodmaprc]"

$ gconftool-2 --set "/desktop/gnome/peripherals/keyboard/general/update_handlers"
  --type list --list-type string "[.xmodmaprc]"
</pre>
<p>At this point you probably need to logout and log back in.</p>
<p>Now, for the case where <span style="font-weight: bold;">xev</span> doesn&#8217;t already detect the key. Start by tailing the <span style="font-weight: bold;">/var/log/messeges</span> file:</p>
<pre>
$ sudo tail -f /var/log/messages
</pre>
<p>The last lines of the file will be displayed. Now, press the desired key. Now, you should see something like</p>
<pre>
Aug 27 13:55:58 darkworld kernel: atkbd.c: Unknown key pressed (translated set 2, code 0x96 on isa0060/serio0).
Aug 27 13:55:58 darkworld kernel: atkbd.c: Use 'setkeycodes e016 &lt;keycode&gt;' to make it known.
Aug 27 13:55:58 darkworld kernel: atkbd.c: Unknown key released (translated set 2, code 0x96 on isa0060/serio0).
Aug 27 13:55:58 darkworld kernel: atkbd.c: Use 'setkeycodes e016 &lt;keycode&gt;' to make it known.
</keycode></keycode></pre>
<p>So, as suggested, we make it known by:</p>
<pre>
$ setkeycodes e016 187
</pre>
<p>I chose 187 since it doesn&#8217;t appear to be used by any key yet. Once all the keycodes have been set, repeat as before to assign the key symbols.</p>
<p>[Edit (Sept. 8, 2005)]<br />
It seems that there is a better way to choose the kernel keycode. We can run <span style="font-weight: bold;">getkeycodes</span> to see which keycodes  are currently in use. We can use any keycode between 84 and 255 that is not already used.</p>
<pre>
$ getkeycodes
Plain scancodes xx (hex) versus keycodes (dec)
for 1-83 (0x01-0x53) scancode equals keycode

0x50:   80  81  82  83  99   0  86  87
0x58:   88 117   0   0  95 183 184 185
0x60:    0   0   0   0   0   0   0   0
0x68:    0   0   0   0   0   0   0   0
0x70:   93   0   0  89   0   0  85  91
0x78:   90  92   0  94   0 124 121   0

Escaped scancodes e0 xx (hex)

e0 00:    0 195 196 197 198   0   0   0
e0 08:    0   0   0   0   0   0   0   0
e0 10:  165   0   0   0   0   0   0   0
e0 18:    0 163   0   0  96  97   0   0
e0 20:  113 140 164   0 166   0   0   0
e0 28:    0   0 255   0   0   0 114   0
e0 30:  115   0 150   0   0  98 255  99
e0 38:  100   0   0   0   0   0   0   0
e0 40:    0   0   0   0   0 119 119 102
e0 48:  103 104   0 105 112 106 118 107
e0 50:  108 109 110 111   0   0   0   0
e0 58:    0   0   0 125 126 127 116 142
e0 60:    0   0   0 143   0 217 156 173
e0 68:  128 159 158 157 155 226   0 112
e0 70:    0   0   0   0   0   0   0   0
e0 78:    0   0   0   0   0   0   0   0
</pre>
<p>It also seems we need to restore the kernel keycode mapping after every reboot. This is easily accomplished by having the required commands in <span style="font-weight:bold;">/etc/rc.local</span>:</p>
<pre>
[darkknight@darkworld ~]$ cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

setkeycodes e016 187 e015 188 e014 189 e013 190 e005 191
            e01e 192 e009 193 e00b 202 e008 194 e018 199
            e00a 200 e017 201 e03b 203 e03c 204 e03d 205
            e03e 206 e03f 207 e040 208 e041 211 e042 210
            e043 212 e023 213 e057 214 e058 215 e064 216
</pre>
<p>The kernel keycodes are different from the keycodes used by X. So, we need to run <span style="font-weight:bold;">xev</span> again to get the keycodes (as seen by X) of the newly found keys.</p>
<p>Got the hints from <a href="http://linux.seindal.dk/item65.html">here</a>.<br />
[End Edit]</p>
<p>Now that we have KeySymbols, what do we do with them? Open up <span style="font-weight: bold;">gconf-editor</span> and browse to the key <span style="font-weight: bold;">/apps/metacity/global_keybindings</span>.  There, choose any of the <span style="font-weight: bold;">run_command_*</span> keys marked as disabled and change the value to the desired KeySymbol (e.g. XF86AudioPrev). Then navigate to the key <span style="font-weight: bold;">/apps/metacity/keybinding_commands</span> and find the <span style="font-weight: bold;">command_*</span> key with the same number as the <span style="font-weight: bold;">run_command_*</span>. Change the value of the key to whatever command you wish to be performed when the <span style="font-weight: bold;">Previous</span> key is pressed. If you happen to run out of <span style="font-weight: bold;">run_command_*</span> and <span style="font-weight: bold;">command_*</span> key pairs, simply create new pairs from the right click menu.</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2005/08/custom-keybinding-gnome/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

