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