The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 5 | <title>Android - Porting Guide</title> |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 6 | <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=internal-codesite" type="text/javascript"></script> |
| 7 | <script src="http://code.google.com/js/jquery.js" type="text/javascript"></script> |
| 8 | <script type="text/javascript">var _tocPath_ = 'http://code.google.com/android/_toc.ezt';</script> |
| 9 | <script src="http://code.google.com/js/codesite.pack.01312008.js" type="text/javascript"></script> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 10 | <script language="JavaScript"> |
| 11 | function resizeHeight() { |
| 12 | if(document.getElementById && !(document.all)) { |
| 13 | height= document.getElementById('doxygen').contentDocument.body.scrollHeight + 20; |
| 14 | document.getElementById('doxygen').style.height = height; |
| 15 | } |
| 16 | else if(document.all) { |
| 17 | height= document.frames('doxygen').document.body.scrollHeight + 20; |
| 18 | document.all.doxygen.style.height = height; |
| 19 | } |
| 20 | } |
| 21 | </script> |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | <link href="http://code.google.com/css/codesite.pack.01312008.css" type="text/css" rel="stylesheet"> |
| 23 | </link> |
| 24 | |
| 25 | <!--[if IE]><link rel="stylesheet" type="text/css" href="/css/iehacks.css" /><![endif]--> |
| 26 | <script src="http://code.google.com/android/assets/search_autocomplete.js"></script> |
| 27 | <link rel="stylesheet" type="text/css" href="http://code.google.com/css/semantic_headers.css" /> |
| 28 | <link rel="stylesheet" type="text/css" href="http://code.google.com/android/assets/style.css" /> |
| 29 | <script> |
| 30 | jQuery(document).ready(function() { |
| 31 | jQuery("pre").addClass("prettyprint"); |
| 32 | }); |
| 33 | </script> |
| 34 | <style type="text/css"> |
| 35 | <!-- |
| 36 | h1,h2,h3 { |
| 37 | color: #000000; |
| 38 | } |
| 39 | --> |
| 40 | </style> |
| 41 | </head> |
| 42 | <body class="gc-documentation"> |
| 43 | <div id="gc-container"> |
| 44 | <a name="top"></a> |
| 45 | <div id="skipto"> </div> |
| 46 | <div id="langpref"> |
| 47 | <!--<a class="dropdown" href="/">English</a> <span>|</span> <a href="/more/">Site Directory</a> --> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 48 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | </div> |
| 50 | <div id="gc-header"> |
| 51 | <div id="logo"><a href="http://code.google.com/android/index.html"><img src="http://code.google.com/android/images/logo_android.gif" alt="Android"/></a></div> |
| 52 | <div id="search" style="inline"> |
| 53 | <div id="searchForm" class="searchForm" style="height: 44px;"> |
| 54 | <!--previously form was here--> |
| 55 | </div> |
| 56 | <!-- end searchForm --> |
| 57 | <noscript> |
| 58 | <style type="text/css"> |
| 59 | .searchForm { |
| 60 | display : none !important; |
| 61 | } |
| 62 | .searchForm2 { |
| 63 | display : inline !important; |
| 64 | } |
| 65 | </style> |
| 66 | </noscript> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 67 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 68 | <div id="searchForm2" class="searchForm2" style="display:none"> |
| 69 | <form id="searchbox_001456098540849067467:6whlsytkdqg" action="http://www.google.com/cse"> |
| 70 | <input type="hidden" name="cx" value="001456098540849067467:6whlsytkdqg" /> |
| 71 | <input type="hidden" name="cof" value="FORID:0" /> |
| 72 | <input type="text" name="q" maxlength="2048" size="41" autocomplete="off" title="Google Code Search"/> |
| 73 | <input type="submit" name="sa" value="Search" title="Search"/> |
| 74 | <br/> |
| 75 | <div class="greytext">e.g. "ajax apis" or "open source"</div> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 76 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | </form> |
| 78 | </div> |
| 79 | <!-- end searchForm2 --> |
| 80 | </div> |
| 81 | <!-- end search --> |
| 82 | </div> |
| 83 | <!-- end gc-header --> |
| 84 | <div id="searchControl" class="search-control"></div> |
| 85 | <!--[if IE]><iframe id="backiFrame" name="backiFrame" src='/dummy.html' style="display:none"></iframe><![endif]--> |
| 86 | <div id="codesiteContent"> |
| 87 | <a name="gc-topnav-anchor"></a> |
| 88 | <div id="gc-topnav"> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 89 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 90 | <h1>Android Platform Development Kit</h1> |
| 91 | <ul class="gc-topnav-tabs"> |
| 92 | <li id="sdk_link"> <a href="http://code.google.com/android/index.html" title="Android Software Development Kit">SDK</a> </li> |
| 93 | <li id="docs_link"> <a href="index.html" title="Official Android documentation">Docs</a> </li> |
| 94 | <li id="faq_link"> <a href="http://code.google.com/android/kb/index.html" title="Answers to frequently asked questions about Android">FAQ</a> </li> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 95 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 96 | <li> <a href="http://android-developers.blogspot.com/" title="Official Android blog">Blog</a> </li> |
| 97 | <li> <a href="http://code.google.com/android/groups.html" title="Android developer forum">Group</a> </li> |
| 98 | <li> <a href="http://code.google.com/android/terms.html" title="Android terms of service">Terms</a> </li> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 99 | <li> <a href="mailto:android-pdk-feedback@google.com?subject=PDK%20Feedback&body=(filed%20from:%20eymaps_keyboard_input.html%20v0.6%20-%2025%20November%202008)%0D%0A%0D%0ASUMMARY:%0D%0A%0D%0A%0D%0A%0D%0ASTEPS%20TO%20REPRODUCE:%0D%0A%0D%0A%0D%0A%0D%0AADDITIONAL%20NOTES:">Report a Problem</a> </li> |
| 100 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 101 | </ul> |
| 102 | </div> |
| 103 | <!-- end gc-topnav --> |
| 104 | <div class="g-section g-tpl-180"> |
| 105 | <a name="gc-toc"></a> |
| 106 | <div class="g-unit g-first" id="gc-toc"> |
| 107 | <ul> |
| 108 | <li> |
| 109 | <h1><a href="index.html">Documentation</a></h1> |
| 110 | <ul> |
| 111 | <li> <strong>Introduction</strong> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 112 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 113 | <ul> |
| 114 | <li><a href="system_requirements.html">Device Requirements</a></li> |
| 115 | </ul> |
| 116 | </li> |
| 117 | <li> <strong>Dev Environment Setup</strong> |
| 118 | <ul> |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 119 | <li><a href="build_system.html">Build System</a></li> |
| 120 | </ul> |
| 121 | </li> |
| 122 | <li> <strong>Basic Bring up</strong> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 123 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 124 | <ul> |
| 125 | <li><a href="build_new_device.html">Building New Device</a></li> |
| 126 | <li><a href="bring_up.html">Bring up</a></li> |
| 127 | <li><a href="keymaps_keyboard_input.html">Keymaps and Keyboard</a></li> |
| 128 | <li><a href="display_drivers.html">Display Drivers</a></li> |
| 129 | </ul> |
| 130 | </li> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 131 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 132 | <li> <strong>Multimedia</strong> |
| 133 | <ul> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 134 | <li><a href="audio_sub_system.html">Audio</a></li> |
| 135 | <li><a href="camera.html">Camera</a></li> |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 | </ul> |
| 137 | </li> |
| 138 | <li> <strong>Power Management</strong> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 139 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 140 | <ul> |
| 141 | <li><a href="power_management.html">Power Management</a></li> |
| 142 | </ul> |
| 143 | </li> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 144 | |
| 145 | <li> <strong>Networking</strong> |
| 146 | <ul> |
| 147 | <li><a href="wifi.html">Wi-Fi</a></li> |
| 148 | <li><a href="gps.html">GPS</a></li> |
| 149 | <li><a href="bluetooth.html">Bluetooth</a></li> |
| 150 | </ul> |
| 151 | </li> |
| 152 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 153 | <li> <strong>Telephony</strong> |
| 154 | <ul> |
| 155 | <li><a href="telephony.html">Radio Interface Layer</a></li> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 156 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 157 | </ul> |
| 158 | </li> |
| 159 | <li> <strong>Testing</strong> |
| 160 | <ul> |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 161 | <li><a href="instrumentation_testing.html">Instrumentation Testing</a></li> |
| 162 | </ul> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 163 | |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 164 | </li> |
| 165 | </ul> |
| 166 | </li> |
| 167 | </ul> |
| 168 | </div> |
| 169 | <a name="gc-pagecontent"></a> |
| 170 | <div class="g-unit" id="gc-pagecontent"> |
| 171 | <div id="jd-content"> |
| 172 | <div class="jd-descr"> |
| 173 | |
| 174 | |
| 175 | <a name="androidKeymapTitle"></a><h1>Keymaps and Keyboard Input</h1> |
| 176 | |
| 177 | |
| 178 | |
| 179 | <a name="toc"/> |
| 180 | <div style="padding:10px"> |
| 181 | <a href="#androidKeymapIntro">Introduction</a><br/> |
| 182 | <a href="#androidKeymapFunctionality">Functionality</a><br/> |
| 183 | <a href="#androidKeymapKeyLayoutMapTitle">Key Layout Map</a><br/><div style="padding-left:40px"> |
| 184 | |
| 185 | <a href="#androidKeymapKeyLayoutMapSelection">Selection of a Key Layout Map</a><br/> |
| 186 | <a href="#androidKeymapKeyLayoutMapFileFormat">File Format</a><br/> |
| 187 | <a href="#androidKeymapKeyLayoutMapExample">Example of a Key Layout Map File</a><br/></div> |
| 188 | <a href="#androidKeymapKeyCharMap">Key Character Map</a><br/><div style="padding-left:40px"> |
| 189 | |
| 190 | <a href="#androidKeymapKeyCharMapSelection">Selection of a Key Character Map</a><br/> |
| 191 | <a href="#androidKeymapKeyCharMapFileFormat">File Format</a><br/> |
| 192 | <a href="#androidKeymapKeyCharMapExample">Example of a Key Character Map File</a><br/> |
| 193 | <a href="#androidKeymapKeyCharMapResourceBinaryFileFormat">Resource Binary File Format</a><br/></div> |
| 194 | <a href="#androidKeymapDriverTemplate">Implementing Your Own Driver (Driver Template)</a><br/> |
| 195 | <a href="#androidKeymapKeyCharMapSampleImplementation">Sample Implementation</a><br/></div></font></div> |
| 196 | |
| 197 | <a name="androidKeymapIntro"></a><h2>Introduction</h2> |
| 198 | |
| 199 | <p>This document describes how keyboard input gets translated into Android actions and how you can customize key layout and key character maps to match the needs of your own device. </p> |
| 200 | <p>Android uses the standard Linux input event device (<code>/dev/event0</code>) and driver as described in the <code>linux/input.h</code> kernel header file. For more information regarding standard Linux input drivers, please see <a href="http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.24.y.git;a=blob;f=Documentation/input/input.txt">Linux Input drivers</a> at <a href="http://kernel.org">http://kernel.org</a>.</p> |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | <a name="androidKeymapFunctionality"></a><h2>Functionality</h2> |
| 206 | |
| 207 | <p>Android's input event device is structured around an interrupt or polling routine that captures the device-specific scancode and converts it to a standard form acceptable to Linux (as defined in <code>input.h</code>) before passing it to the kernel with <code>input_event()</code>.</p> |
| 208 | <p>The keymap driver's other primary function is to establish a probe function that sets up the interrupt or polling function, handles hardware initialization, and attaches the driver to the input subsystem with <code>input_register_device()</code>.</p> |
| 209 | <p>The table below describes the steps required to translate from keyboard input to application action: </p> |
| 210 | <table border=1> |
| 211 | <tbody><tr> |
| 212 | <th scope="col">Step</th> |
| 213 | <th scope="col">Action</th> |
| 214 | <th scope="col">Explanation</th> |
| 215 | </tr> |
| 216 | <tr> |
| 217 | <td>1.</td> |
| 218 | <td>Window manager reads key event from Linux keyboard driver. </td> |
| 219 | <td>Events are typically positional. For example, the top-left position on a keypad returns 16 regardless of whether that key is printed with a Q (as on a QWERTY keypad) or an A (as on an AZERTY keypads). This first conversion by the Linux Keyboard Driver yields a scancode (for example, 16).</td> |
| 220 | </tr> |
| 221 | <tr> |
| 222 | <td>2. </td> |
| 223 | <td>Window manager maps scancode to keycode.</td> |
| 224 | <td>When the window manager reads a key event out of the driver, it maps the scancode to a keycode using a key layout map file. Typically, the keycode is the primary symbol screen-printed on a key. For example, <code>KEYCODE_DPAD_CENTER</code> is the center button on the five-way navigation control. Even though ALT + G generates a "?" character, <code>KEYCODE_G</code> is the keycode.</td> |
| 225 | </tr> |
| 226 | <tr> |
| 227 | <td>3. </td> |
| 228 | <td>Window manager sends both the scancode and the keycode to the application.</td> |
| 229 | <td>Both the scancode and keycode are handled by the view with focus. |
| 230 | How the application interprets both depend on the application.</td> |
| 231 | </tr> |
| 232 | </tbody> |
| 233 | </table> |
| 234 | |
| 235 | |
| 236 | <a name="androidKeymapKeyLayoutMapTitle"></a><h2>Key Layout Map</h2> |
| 237 | |
| 238 | |
| 239 | |
| 240 | <a name="androidKeymapKeyLayoutMapSelection"></a><h3>Selection of a Key Layout Map</h3> |
| 241 | |
| 242 | <p>Key layout maps are installed in <code>/system/usr/keylayout</code> and <code>/data/usr/keylayout</code>.</p> |
| 243 | <p>For each keyboard device xxx, set the <code>android.keylayout.xxx</code> system property (see <a href="build_new_device.html">Building New Device</a> for help setting system properties). If you don't specify a keylayout file, Android will default to <code>/system/usr/keylayout/qwerty.kl</code>.</p> |
| 244 | |
| 245 | |
| 246 | <a name="androidKeymapKeyLayoutMapFileFormat"></a><h3>File Format</h3> |
| 247 | |
| 248 | <p>Key layout maps are stored on the device as UTF-8 text files and have the following characteristics:</p> |
| 249 | <p><ul> |
| 250 | <li>Comments: The pound symbol (#) denotes a comment and everything after the pound symbol on a line is ignored.</li> |
| 251 | <li>Whitespace: All empty lines are ignored.</li> |
| 252 | <li>Key definitions: Key definitions follow the syntax <code>key SCANCODE KEYCODE [FLAGS...]</code>, where <code>SCANCODE</code> is a number, <code>KEYCODE</code> is defined in your specific keylayout file (<code>android.keylayout.xxx</code>), and potential <code>FLAGS</code> are defined as follows: |
| 253 | <ul><li>SHIFT: While pressed, the shift key modifier is set</li> |
| 254 | <li>ALT: While pressed, the alt key modifier is set</li> |
| 255 | <li>CAPS: While pressed, the caps lock key modifier is set</li> |
| 256 | <li>WAKE: When this key is pressed while the device is asleep, the device will wake up and the key event gets sent to the app.</li> |
| 257 | <li>WAKE_DROPPED: When this key is pressed while the device is asleep, the device will wake up and the key event does not get sent to the app.</li> |
| 258 | </ul> |
| 259 | </li> |
| 260 | </ul> |
| 261 | </p> |
| 262 | |
| 263 | |
| 264 | <a name="androidKeymapKeyLayoutMapExample"></a><h3>Example of a Key Layout Map File</h3> |
| 265 | |
| 266 | <p>The following code comes from <code>android/src/device/product/generic/tuttle2.kl</code> and is an example of a complete key layout file:</p> |
| 267 | <pre class="prettify"> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 268 | # Copyright 2007 Google Inc. |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 269 | |
| 270 | key 2 1 |
| 271 | key 3 2 |
| 272 | key 4 3 |
| 273 | key 5 4 |
| 274 | key 6 5 |
| 275 | key 7 6 |
| 276 | key 8 7 |
| 277 | key 9 8 |
| 278 | key 10 9 |
| 279 | key 11 0 |
| 280 | key 158 BACK WAKE_DROPPED |
| 281 | key 230 SOFT_RIGHT WAKE |
| 282 | key 60 SOFT_RIGHT WAKE |
| 283 | key 107 ENDCALL WAKE_DROPPED |
| 284 | key 62 ENDCALL WAKE_DROPPED |
| 285 | key 229 MENU WAKE_DROPPED |
| 286 | key 59 MENU WAKE_DROPPED |
| 287 | key 228 POUND |
| 288 | key 227 STAR |
| 289 | key 231 CALL WAKE_DROPPED |
| 290 | key 61 CALL WAKE_DROPPED |
| 291 | key 232 DPAD_CENTER WAKE_DROPPED |
| 292 | key 108 DPAD_DOWN WAKE_DROPPED |
| 293 | key 103 DPAD_UP WAKE_DROPPED |
| 294 | key 102 HOME WAKE |
| 295 | key 105 DPAD_LEFT WAKE_DROPPED |
| 296 | key 106 DPAD_RIGHT WAKE_DROPPED |
| 297 | key 115 VOLUME_UP |
| 298 | key 114 VOLUME_DOWN |
| 299 | key 116 POWER WAKE |
| 300 | key 212 SLASH |
| 301 | |
| 302 | key 16 Q |
| 303 | key 17 W |
| 304 | key 18 E |
| 305 | key 19 R |
| 306 | key 20 T |
| 307 | key 21 Y |
| 308 | key 22 U |
| 309 | key 23 I |
| 310 | key 24 O |
| 311 | key 25 P |
| 312 | |
| 313 | key 30 A |
| 314 | key 31 S |
| 315 | key 32 D |
| 316 | key 33 F |
| 317 | key 34 G |
| 318 | key 35 H |
| 319 | key 36 J |
| 320 | key 37 K |
| 321 | key 38 L |
| 322 | key 14 DEL |
| 323 | |
| 324 | key 44 Z |
| 325 | key 45 X |
| 326 | key 46 C |
| 327 | key 47 V |
| 328 | key 48 B |
| 329 | key 49 N |
| 330 | key 50 M |
| 331 | key 51 COMMA |
| 332 | key 52 PERIOD |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 333 | key 28 NEWLINE |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 334 | |
| 335 | key 56 ALT_LEFT |
| 336 | key 42 SHIFT_LEFT |
| 337 | key 215 AT |
| 338 | key 57 SPACE |
| 339 | key 53 SLASH |
| 340 | key 127 SYM |
| 341 | key 100 ALT_LEFT |
| 342 | |
| 343 | key 399 GRAVE |
| 344 | </pre> |
| 345 | |
| 346 | |
| 347 | <a name="androidKeymapKeyCharMap"></a><h2>Key Character Map</h2> |
| 348 | |
| 349 | |
| 350 | |
| 351 | <a name="androidKeymapKeyCharMapSelection"></a><h3>Selection of a Key Character Map</h3> |
| 352 | |
| 353 | <p>Key character maps are installed in <code>/system/usr/keychars</code> and <code>/data/usr/keychars</code>.</p> |
| 354 | <p>For each keyboard device xxx, set the <code>android.keychar.xxx</code> system property to the full path of the desired keychar file. If you don't specify a keychar file, Android will default to <code>/system/usr/keychar/qwerty.kl</code>. |
| 355 | |
| 356 | |
| 357 | <a name="androidKeymapKeyCharMapFileFormat"></a><h3>File Format</h3> |
| 358 | |
| 359 | <p>Key character maps are stored on the device as binary resources in order to reduce loading time. Key character maps have the following characteristics:</p> |
| 360 | <p><ul> |
| 361 | |
| 362 | <li>Comments: The pound symbol (#) denotes a comment and everything after the pound symbol on a line is ignored.</li> |
| 363 | <li>Whitespace: All empty lines are ignored.</li> |
| 364 | <li>Column definitions: Column definitions follow the syntax <code>columns MODIFIERS [...]</code>, where <code>MODIFIERS</code> are defined as follows: |
| 365 | <table border=1 cellpadding=2 cellspacing=0> |
| 366 | <tbody><tr> |
| 367 | <th scope="col">Character in MODIFIERS</th> |
| 368 | <th scope="col">Corresponding bit in the modifiers</th> |
| 369 | </tr> |
| 370 | <tr> |
| 371 | <td>O</td> |
| 372 | <td>no modifiers</td> |
| 373 | </tr> |
| 374 | <tr> |
| 375 | <td>S</td> |
| 376 | <td>MODIFIER_SHIFT</td> |
| 377 | </tr> |
| 378 | <tr> |
| 379 | <td>C</td> |
| 380 | <td>MODIFIER_CONTROL</td> |
| 381 | </tr> |
| 382 | <tr> |
| 383 | <td>L</td> |
| 384 | <td>MODIFIER_CAPS_LOCK</td> |
| 385 | </tr> |
| 386 | <tr> |
| 387 | <td>A</td> |
| 388 | <td>MODIFIER_ALT</td> |
| 389 | </tr> |
| 390 | </table> |
| 391 | </li> |
| 392 | <li>Key definitions: Key definitions have the syntax <code>key SCANCODE CHARACTER [...]</code> where <code>SCANCODE</code> is a number and <code>CHARACTER</code> values are either UTF-8 characters in quotation marks (for example, "a") or a numeric value that <code>strtol</code> can parse.</li> |
| 393 | </ul></p> |
| 394 | |
| 395 | |
| 396 | <a name="androidKeymapKeyCharMapExample"></a><h3>Example of a Key Character Map File</h3> |
| 397 | |
| 398 | <p>The following code comes from <code>android/src/device/product/generic/tuttle2.kcm</code> and represents a complete key character file:</p> |
| 399 | <p>The type line indicates what kind of keyboard your device implements. Possible types include:</p> |
| 400 | <p><ul> |
| 401 | <li><b>NUMERIC</b>: A numeric (12-key) keyboard.</li> |
| 402 | <li><b>Q14</b>: A keyboard that includes all letters but multiple letters per key.</li> |
| 403 | <li><b>QWERTY</b>: A keyboard with all letters and possibly numbers. This option applies to all full keyboard configurations, such as AZERTY.</li> |
| 404 | </ul> |
| 405 | </p> |
| 406 | <pre class="prettify"> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 407 | # Copyright 2007 Google Inc. |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 408 | |
| 409 | [type=QWERTY] |
| 410 | |
| 411 | # keycode base caps fn caps_fn number display_label |
| 412 | |
| 413 | A 'a' 'A' '%' 0x00 '%' 'A' |
| 414 | B 'b' 'B' '=' 0x00 '=' 'B' |
| 415 | C 'c' 'C' '8' 0x00E7 '8' 'C' |
| 416 | D 'd' 'D' '5' 0x00 '5' 'D' |
| 417 | E 'e' 'E' '2' 0x0301 '2' 'E' |
| 418 | F 'f' 'F' '6' 0x00A5 '6' 'F' |
| 419 | G 'g' 'G' '-' '_' '-' 'G' |
| 420 | H 'h' 'H' '[' '{' '[' 'H' |
| 421 | I 'i' 'I' '$' 0x0302 '$' 'I' |
| 422 | J 'j' 'J' ']' '}' ']' 'J' |
| 423 | K 'k' 'K' '"' '~' '"' 'K' |
| 424 | L 'l' 'L' ''' '`' ''' 'L' |
| 425 | M 'm' 'M' '>' 0x00 '>' 'M' |
| 426 | N 'n' 'N' '<' 0x0303 '<' 'N' |
| 427 | O 'o' 'O' '(' 0x00 '(' 'O' |
| 428 | P 'p' 'P' ')' 0x00 ')' 'P' |
| 429 | Q 'q' 'Q' '*' 0x0300 '*' 'Q' |
| 430 | R 'r' 'R' '3' 0x20AC '3' 'R' |
| 431 | S 's' 'S' '4' 0x00DF '4' 'S' |
| 432 | T 't' 'T' '+' 0x00A3 '+' 'T' |
| 433 | U 'u' 'U' '&' 0x0308 '&' 'U' |
| 434 | V 'v' 'V' '9' '^' '9' 'V' |
| 435 | W 'w' 'W' '1' 0x00 '1' 'W' |
| 436 | X 'x' 'X' '7' 0xEF00 '7' 'X' |
| 437 | Y 'y' 'Y' '!' 0x00A1 '!' 'Y' |
| 438 | Z 'z' 'Z' '#' 0x00 '#' 'Z' |
| 439 | |
| 440 | COMMA ',' ';' ';' '|' ',' ',' |
| 441 | PERIOD '.' ':' ':' 0x2026 '.' '.' |
| 442 | AT '@' '0' '0' 0x2022 '0' '@' |
| 443 | SLASH '/' '?' '?' '\' '/' '/' |
| 444 | |
| 445 | SPACE 0x20 0x20 0x9 0x9 0x20 0x20 |
| 446 | NEWLINE 0xa 0xa 0xa 0xa 0xa 0xa |
| 447 | |
| 448 | # on pc keyboards |
| 449 | TAB 0x9 0x9 0x9 0x9 0x9 0x9 |
| 450 | 0 '0' ')' ')' ')' '0' '0' |
| 451 | 1 '1' '!' '!' '!' '1' '1' |
| 452 | 2 '2' '@' '@' '@' '2' '2' |
| 453 | 3 '3' '#' '#' '#' '3' '3' |
| 454 | 4 '4' '$' '$' '$' '4' '4' |
| 455 | 5 '5' '%' '%' '%' '5' '5' |
| 456 | 6 '6' '^' '^' '^' '6' '6' |
| 457 | 7 '7' '&' '&' '&' '7' '7' |
| 458 | 8 '8' '*' '*' '*' '8' '8' |
| 459 | 9 '9' '(' '(' '(' '9' '9' |
| 460 | |
| 461 | GRAVE '`' '~' '`' '~' '`' '`' |
| 462 | MINUS '-' '_' '-' '_' '-' '-' |
| 463 | EQUALS '=' '+' '=' '+' '=' '=' |
| 464 | LEFT_BRACKET '[' '{' '[' '{' '[' '[' |
| 465 | RIGHT_BRACKET ']' '}' ']' '}' ']' ']' |
| 466 | BACKSLASH '\' '|' '\' '|' '\' '\' |
| 467 | SEMICOLON ';' ':' ';' ':' ';' ';' |
| 468 | APOSTROPHE ''' '"' ''' '"' ''' ''' |
| 469 | STAR '*' '*' '*' '*' '*' '*' |
| 470 | POUND '#' '#' '#' '#' '#' '#' |
| 471 | PLUS '+' '+' '+' '+' '+' '+' |
| 472 | </pre> |
| 473 | |
| 474 | |
| 475 | <a name="androidKeymapKeyCharMapResourceBinaryFileFormat"></a><h3>Resource Binary File Format</h3> |
| 476 | |
| 477 | <p>The file snippet above gets converted to the following by the <code>makekcharmap</code> tool as part of the build process. You can <code>mmap</code> this file in and share the approximately 4k of memory that it uses between processes to minimize load time.</p> |
| 478 | <table> |
| 479 | <tbody><tr> |
| 480 | <th scope="col">Offset</th> |
| 481 | |
| 482 | <th scope="col">Size (bytes)</th> |
| 483 | <th scope="col">Description</th> |
| 484 | </tr> |
| 485 | <tr> |
| 486 | <td>0x00-0x0b</td> |
| 487 | <td></td> |
| 488 | <td>The ascii value "keycharmap1" including the null character</td> |
| 489 | |
| 490 | </tr> |
| 491 | <tr> |
| 492 | <td>0x0c-0x0f</td> |
| 493 | <td></td> |
| 494 | <td>padding</td> |
| 495 | </tr> |
| 496 | <tr> |
| 497 | <td>0x10-0x13</td> |
| 498 | |
| 499 | <td></td> |
| 500 | <td>The number of entries in the modifiers table (COLS)</td> |
| 501 | </tr> |
| 502 | <tr> |
| 503 | <td>0x14-0x17</td> |
| 504 | <td></td> |
| 505 | <td>The number of entries in the characters table (ROWS)</td> |
| 506 | |
| 507 | </tr> |
| 508 | <tr> |
| 509 | <td>0x18-0x1f</td> |
| 510 | <td></td> |
| 511 | <td>padding</td> |
| 512 | </tr> |
| 513 | <tr> |
| 514 | <td></td> |
| 515 | |
| 516 | <td>4*COLS</td> |
| 517 | <td>Modifiers table. The modifier mask values that each of the |
| 518 | columns in the characters table correspond to.</td> |
| 519 | </tr> |
| 520 | <tr> |
| 521 | <td></td> |
| 522 | <td></td> |
| 523 | <td>padding to the next 16 byte boundary</td> |
| 524 | |
| 525 | </tr> |
| 526 | <tr> |
| 527 | <td></td> |
| 528 | <td>4*COLS*ROWS</td> |
| 529 | <td>Characters table. The modifier mask values that each of the |
| 530 | columns correspond to.</td> |
| 531 | </tr> |
| 532 | </tbody></table> |
| 533 | |
| 534 | |
| 535 | <a name="androidKeymapDriverTemplate"></a><h2>Implementing Your Own Driver (Driver Template)</h2> |
| 536 | |
| 537 | <p>The following file, <code>pguide_events.c</code>, illustrates how to implement an Android keymap driver.</p> |
| 538 | <pre class="prettyprint"> |
| 539 | /* |
| 540 | * pguide_events.c |
| 541 | * |
| 542 | * ANDROID PORTING GUIDE: INPUT EVENTS DRIVER TEMPLATE |
| 543 | * |
| 544 | * This template is designed to an example of the functionality |
| 545 | * necessary for Android to recieve input events. The PGUIDE_EVENT |
| 546 | * macros are meant as pointers indicating where to implement the |
| 547 | * hardware specific code necessary for the new device. The existence |
| 548 | * of the macros is not meant to trivialize the work required, just as |
| 549 | * an indication of where the work needs to be done. |
| 550 | * |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 551 | * Copyright 2007, Google Inc. |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 552 | * Based on goldfish-events.c |
| 553 | * |
| 554 | */ |
| 555 | |
| 556 | #include <linux/module.h> |
| 557 | #include <linux/init.h> |
| 558 | #include <linux/interrupt.h> |
| 559 | #include <linux/types.h> |
| 560 | #include <linux/input.h> |
| 561 | #include <linux/kernel.h> |
| 562 | #include <linux/platform_device.h> |
| 563 | |
| 564 | |
| 565 | #include <asm/irq.h> |
| 566 | #include <asm/io.h> |
| 567 | |
| 568 | |
| 569 | |
| 570 | #define PGUIDE_EVENTS_INTERRUPT do{} while(0) |
| 571 | #define PGUIDE_EVENTS_PROBE do{} while(0) |
| 572 | |
| 573 | struct event_dev { |
| 574 | struct input_dev *input; |
| 575 | int irq; |
| 576 | }; |
| 577 | |
| 578 | static irqreturn_t pguide_events_interrupt(int irq, void *dev_id) |
| 579 | { |
| 580 | struct event_dev *edev = dev_id; |
| 581 | unsigned type=0, code=0, value=0; |
| 582 | |
| 583 | /* Set up type, code, and value per input.h |
| 584 | */ |
| 585 | PGUIDE_EVENTS_INTERRUPT; |
| 586 | |
| 587 | input_event(edev->input, type, code, value); |
| 588 | return IRQ_HANDLED; |
| 589 | } |
| 590 | |
| 591 | static int pguide_events_probe(struct platform_device *pdev) |
| 592 | { |
| 593 | struct input_dev *input_dev; |
| 594 | struct event_dev *edev; |
| 595 | |
| 596 | printk("*** pguide events probe ***\n"); |
| 597 | |
| 598 | edev = kzalloc(sizeof(struct event_dev), GFP_KERNEL); |
| 599 | input_dev = input_allocate_device(); |
| 600 | |
| 601 | /* Setup edev->irq and do any hardware init */ |
| 602 | PGUIDE_EVENTS_PROBE; |
| 603 | |
| 604 | if(request_irq(edev->irq, pguide_events_interrupt, 0, |
| 605 | "pguide_events", edev) < 0) { |
| 606 | goto fail; |
| 607 | } |
| 608 | |
| 609 | /* indicate that we generate key events */ |
| 610 | set_bit(EV_KEY, input_dev->evbit); |
| 611 | set_bit(EV_REL, input_dev->evbit); |
| 612 | set_bit(EV_ABS, input_dev->evbit); |
| 613 | |
| 614 | /* indicate that we generate *any* key event */ |
| 615 | |
| 616 | bitmap_fill(input_dev->keybit, KEY_MAX); |
| 617 | bitmap_fill(input_dev->relbit, REL_MAX); |
| 618 | bitmap_fill(input_dev->absbit, ABS_MAX); |
| 619 | |
| 620 | platform_set_drvdata(pdev, edev); |
| 621 | |
| 622 | input_dev->name = "pguide_events"; |
| 623 | input_dev->private = edev; |
| 624 | input_dev->cdev.dev = &pdev->dev; |
| 625 | |
| 626 | input_register_device(input_dev); |
| 627 | return 0; |
| 628 | |
| 629 | fail: |
| 630 | kfree(edev); |
| 631 | input_free_device(input_dev); |
| 632 | |
| 633 | return -EINVAL; |
| 634 | } |
| 635 | |
| 636 | static struct platform_driver pguide_events_driver = { |
| 637 | .probe = pguide_events_probe, |
| 638 | .driver = { |
| 639 | .name = "pguide_events", |
| 640 | }, |
| 641 | }; |
| 642 | |
| 643 | static int __devinit pguide_events_init(void) |
| 644 | { |
| 645 | return platform_driver_register(&pguide_events_driver); |
| 646 | } |
| 647 | |
| 648 | |
| 649 | static void __exit pguide_events_exit(void) |
| 650 | { |
| 651 | } |
| 652 | |
| 653 | module_init(pguide_events_init); |
| 654 | module_exit(pguide_events_exit); |
| 655 | |
| 656 | MODULE_DESCRIPTION("Pguide Event Device"); |
| 657 | MODULE_LICENSE("GPL"); |
| 658 | </pre> |
| 659 | |
| 660 | |
| 661 | <a name="androidKeymapKeyCharMapSampleImplementation"></a><h2>Sample Implementation</h2> |
| 662 | |
| 663 | <p>Assume the following for the setup of a new keypad device:</p> |
| 664 | <pre class="prettify"> |
| 665 | android.keylayout.partnerxx_keypad = /system/usr/keylayout/partnerxx_keypad.kl |
| 666 | android.keychar.partnerxx_keypad = /system/usr/keychars/partnerxx.kcm |
| 667 | </pre> |
| 668 | <p>The following example log file indicates that you have correctly registered the new keypad:</p> |
| 669 | <pre class="prettify"> |
| 670 | I/EventHub( 1548): New device: path=/dev/input/event0 name=partnerxx_keypad id=0x10000 (of 0x1) index=1 fd=30 |
| 671 | I/EventHub( 1548): new keyboard input device added, name = partnerxx_keypad |
| 672 | D/WindowManager( 1548): Starting input thread. |
| 673 | D/WindowManager( 1548): Startup complete! |
| 674 | I/EventHub( 1548): New keyboard: name=partnerxx_keypad |
| 675 | keymap=partnerxx_keypad.kl |
| 676 | keymapPath=/system/usr/keychars/partnerxx_keypad.kcm.bin |
| 677 | I/ServiceManager( 1535): ServiceManager: addService(window, 0x13610) |
| 678 | I/EventHub( 1548): Reporting device opened: id=0x10000, name=/dev/input/event0 |
| 679 | I/KeyInputQueue( 1548): Device added: id=0x10000, name=partnerxx_keypad, classes=1 |
| 680 | I/KeyInputQueue( 1548): Keymap: partnerxx_keypad.kl |
| 681 | </pre> |
| 682 | <p>The snippet above contains artificial line breaks to maintain a print-friendly document.</p> |
| 683 | |
| 684 | |
| 685 | <p><span class="lh2"><a name="androidFooter"></a></span> |
| 686 | |
| 687 | </div> |
| 688 | </div> |
| 689 | <!-- end gc-pagecontent --> |
| 690 | </div> |
| 691 | <!-- end gooey wrapper --> |
| 692 | </div> |
| 693 | <!-- end codesearchresults --> |
| 694 | <div id="gc-footer" dir="ltr"> |
| 695 | <div class="text"> ©2008 Google<!-- - <a href="/">Code Home</a> - <a href="http://www.google.com/accounts/TOS">Site Terms of Service</a> - <a href="http://www.google.com/privacy.html">Privacy Policy</a> - <a href="/more">Site Directory</a> --></div> |
| 696 | </div> |
| 697 | <!-- end gc-footer --> |
| 698 | </div> |
| 699 | <!-- end gc-containter --> |
| 700 | <script src="http://www.google-analytics.com/ga.js" type="text/javascript"> |
| 701 | </script> |
| 702 | <script type="text/javascript"> |
| 703 | try { |
| 704 | var pageTracker = _gat._getTracker("UA-18071-1"); |
| 705 | pageTracker._setAllowAnchor(true); |
| 706 | pageTracker._initData(); |
| 707 | pageTracker._trackPageview(); |
| 708 | } catch(e) {} |
| 709 | </script> |
The Android Open Source Project | e943f2f | 2008-12-17 18:04:04 -0800 | [diff] [blame^] | 710 | <div id="jd-build-id"> v0.6 - 25 November 2008</div> |
The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 711 | </div></div></div></body> |
| 712 | </html> |
| 713 | |