📄 keymaps_keyboard_input.html
字号:
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>Android - Porting Guide</title><script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=internal-codesite" type="text/javascript"></script><script src="http://code.google.com/js/jquery.js" type="text/javascript"></script><script type="text/javascript">var _tocPath_ = 'http://code.google.com/android/_toc.ezt';</script><script src="http://code.google.com/js/codesite.pack.01312008.js" type="text/javascript"></script><script language="JavaScript">function resizeHeight() { if(document.getElementById && !(document.all)) { height= document.getElementById('doxygen').contentDocument.body.scrollHeight + 20; document.getElementById('doxygen').style.height = height; } else if(document.all) { height= document.frames('doxygen').document.body.scrollHeight + 20; document.all.doxygen.style.height = height; }}</script><link href="http://code.google.com/css/codesite.pack.01312008.css" type="text/css" rel="stylesheet"></link><!--[if IE]><link rel="stylesheet" type="text/css" href="/css/iehacks.css" /><![endif]--><script src="http://code.google.com/android/assets/search_autocomplete.js"></script><link rel="stylesheet" type="text/css" href="http://code.google.com/css/semantic_headers.css" /><link rel="stylesheet" type="text/css" href="http://code.google.com/android/assets/style.css" /><script> jQuery(document).ready(function() { jQuery("pre").addClass("prettyprint"); }); </script><style type="text/css"><!--h1,h2,h3 { color: #000000;}--></style></head><body class="gc-documentation"><div id="gc-container"><a name="top"></a><div id="skipto"> </div><div id="langpref"> <!--<a class="dropdown" href="/">English</a> <span>|</span> <a href="/more/">Site Directory</a> --></div><div id="gc-header"> <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> <div id="search" style="inline"> <div id="searchForm" class="searchForm" style="height: 44px;"> <!--previously form was here--> </div> <!-- end searchForm --> <noscript> <style type="text/css"> .searchForm { display : none !important; } .searchForm2 { display : inline !important; } </style> </noscript> <div id="searchForm2" class="searchForm2" style="display:none"> <form id="searchbox_001456098540849067467:6whlsytkdqg" action="http://www.google.com/cse"> <input type="hidden" name="cx" value="001456098540849067467:6whlsytkdqg" /> <input type="hidden" name="cof" value="FORID:0" /> <input type="text" name="q" maxlength="2048" size="41" autocomplete="off" title="Google Code Search"/> <input type="submit" name="sa" value="Search" title="Search"/> <br/> <div class="greytext">e.g. "ajax apis" or "open source"</div> </form> </div> <!-- end searchForm2 --> </div> <!-- end search --></div><!-- end gc-header --><div id="searchControl" class="search-control"></div><!--[if IE]><iframe id="backiFrame" name="backiFrame" src='/dummy.html' style="display:none"></iframe><![endif]--><div id="codesiteContent"><a name="gc-topnav-anchor"></a><div id="gc-topnav"> <h1>Android Platform Development Kit</h1> <ul class="gc-topnav-tabs"> <li id="sdk_link"> <a href="http://code.google.com/android/index.html" title="Android Software Development Kit">SDK</a> </li> <li id="docs_link"> <a href="index.html" title="Official Android documentation">Docs</a> </li> <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> <li> <a href="http://android-developers.blogspot.com/" title="Official Android blog">Blog</a> </li> <li> <a href="http://code.google.com/android/groups.html" title="Android developer forum">Group</a> </li> <li> <a href="http://code.google.com/android/terms.html" title="Android terms of service">Terms</a> </li> <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> </ul></div><!-- end gc-topnav --><div class="g-section g-tpl-180"><a name="gc-toc"></a><div class="g-unit g-first" id="gc-toc"> <ul> <li> <h1><a href="index.html">Documentation</a></h1> <ul> <li> <strong>Introduction</strong> <ul> <li><a href="system_requirements.html">Device Requirements</a></li> </ul> </li> <li> <strong>Dev Environment Setup</strong> <ul> <li><a href="build_system.html">Build System</a></li> </ul> </li> <li> <strong>Basic Bring up</strong> <ul> <li><a href="build_new_device.html">Building New Device</a></li> <li><a href="bring_up.html">Bring up</a></li> <li><a href="keymaps_keyboard_input.html">Keymaps and Keyboard</a></li> <li><a href="display_drivers.html">Display Drivers</a></li> </ul> </li> <li> <strong>Multimedia</strong> <ul> <li><a href="audio_sub_system.html">Audio</a></li> <li><a href="camera.html">Camera</a></li> </ul> </li> <li> <strong>Power Management</strong> <ul> <li><a href="power_management.html">Power Management</a></li> </ul> </li> <li> <strong>Networking</strong> <ul> <li><a href="wifi.html">Wi-Fi</a></li> <li><a href="gps.html">GPS</a></li> <li><a href="bluetooth.html">Bluetooth</a></li> </ul> </li> <li> <strong>Telephony</strong> <ul> <li><a href="telephony.html">Radio Interface Layer</a></li> </ul> </li> <li> <strong>Testing</strong> <ul> <li><a href="instrumentation_testing.html">Instrumentation Testing</a></li> </ul> </li> </ul> </li> </ul></div><a name="gc-pagecontent"></a><div class="g-unit" id="gc-pagecontent"><div id="jd-content"><div class="jd-descr"><a name="androidKeymapTitle"></a><h1>Keymaps and Keyboard Input</h1><a name="toc"/><div style="padding:10px"><a href="#androidKeymapIntro">Introduction</a><br/><a href="#androidKeymapFunctionality">Functionality</a><br/><a href="#androidKeymapKeyLayoutMapTitle">Key Layout Map</a><br/><div style="padding-left:40px"><a href="#androidKeymapKeyLayoutMapSelection">Selection of a Key Layout Map</a><br/><a href="#androidKeymapKeyLayoutMapFileFormat">File Format</a><br/><a href="#androidKeymapKeyLayoutMapExample">Example of a Key Layout Map File</a><br/></div><a href="#androidKeymapKeyCharMap">Key Character Map</a><br/><div style="padding-left:40px"><a href="#androidKeymapKeyCharMapSelection">Selection of a Key Character Map</a><br/><a href="#androidKeymapKeyCharMapFileFormat">File Format</a><br/><a href="#androidKeymapKeyCharMapExample">Example of a Key Character Map File</a><br/><a href="#androidKeymapKeyCharMapResourceBinaryFileFormat">Resource Binary File Format</a><br/></div><a href="#androidKeymapDriverTemplate">Implementing Your Own Driver (Driver Template)</a><br/><a href="#androidKeymapKeyCharMapSampleImplementation">Sample Implementation</a><br/></div></font></div><a name="androidKeymapIntro"></a><h2>Introduction</h2><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><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><a name="androidKeymapFunctionality"></a><h2>Functionality</h2><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><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><p>The table below describes the steps required to translate from keyboard input to application action: </p><table border=1> <tbody><tr> <th scope="col">Step</th> <th scope="col">Action</th> <th scope="col">Explanation</th> </tr> <tr> <td>1.</td> <td>Window manager reads key event from Linux keyboard driver. </td> <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> </tr> <tr> <td>2. </td> <td>Window manager maps scancode to keycode.</td> <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> </tr> <tr> <td>3. </td> <td>Window manager sends both the scancode and the keycode to the application.</td> <td>Both the scancode and keycode are handled by the view with focus. How the application interprets both depend on the application.</td> </tr></tbody></table><a name="androidKeymapKeyLayoutMapTitle"></a><h2>Key Layout Map</h2><a name="androidKeymapKeyLayoutMapSelection"></a><h3>Selection of a Key Layout Map</h3><p>Key layout maps are installed in <code>/system/usr/keylayout</code> and <code>/data/usr/keylayout</code>.</p><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><a name="androidKeymapKeyLayoutMapFileFormat"></a><h3>File Format</h3><p>Key layout maps are stored on the device as UTF-8 text files and have the following characteristics:</p><p><ul><li>Comments: The pound symbol (#) denotes a comment and everything after the pound symbol on a line is ignored.</li><li>Whitespace: All empty lines are ignored.</li><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:<ul><li>SHIFT: While pressed, the shift key modifier is set</li><li>ALT: While pressed, the alt key modifier is set</li><li>CAPS: While pressed, the caps lock key modifier is set</li><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><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></ul></li></ul></p><a name="androidKeymapKeyLayoutMapExample"></a><h3>Example of a Key Layout Map File</h3><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><pre class="prettify"># Copyright 2007 Google Inc.key 2 1key 3 2key 4 3key 5 4key 6 5key 7 6key 8 7key 9 8key 10 9key 11 0key 158 BACK WAKE_DROPPEDkey 230 SOFT_RIGHT WAKEkey 60 SOFT_RIGHT WAKEkey 107 ENDCALL WAKE_DROPPEDkey 62 ENDCALL WAKE_DROPPEDkey 229 MENU WAKE_DROPPEDkey 59 MENU WAKE_DROPPEDkey 228 POUNDkey 227 STARkey 231 CALL WAKE_DROPPEDkey 61 CALL WAKE_DROPPEDkey 232 DPAD_CENTER WAKE_DROPPEDkey 108 DPAD_DOWN WAKE_DROPPEDkey 103 DPAD_UP WAKE_DROPPEDkey 102 HOME WAKEkey 105 DPAD_LEFT WAKE_DROPPEDkey 106 DPAD_RIGHT WAKE_DROPPEDkey 115 VOLUME_UPkey 114 VOLUME_DOWNkey 116 POWER WAKEkey 212 SLASHkey 16 Qkey 17 Wkey 18 Ekey 19 Rkey 20 Tkey 21 Ykey 22 Ukey 23 Ikey 24 Okey 25 Pkey 30 Akey 31 Skey 32 Dkey 33 Fkey 34 Gkey 35 Hkey 36 Jkey 37 Kkey 38 Lkey 14 DEL key 44 Zkey 45 Xkey 46 Ckey 47 Vkey 48 Bkey 49 Nkey 50 Mkey 51 COMMAkey 52 PERIODkey 28 NEWLINE key 56 ALT_LEFTkey 42 SHIFT_LEFTkey 215 ATkey 57 SPACEkey 53 SLASHkey 127 SYMkey 100 ALT_LEFTkey 399 GRAVE</pre><a name="androidKeymapKeyCharMap"></a><h2>Key Character Map</h2><a name="androidKeymapKeyCharMapSelection"></a><h3>Selection of a Key Character Map</h3><p>Key character maps are installed in <code>/system/usr/keychars</code> and <code>/data/usr/keychars</code>.</p><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>.<a name="androidKeymapKeyCharMapFileFormat"></a><h3>File Format</h3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -