Home | History | Annotate | Download | only in input
      1 page.title=Validate Keymaps Tool
      2 @jd:body
      3 
      4 <!--
      5     Copyright 2010 The Android Open Source Project
      6 
      7     Licensed under the Apache License, Version 2.0 (the "License");
      8     you may not use this file except in compliance with the License.
      9     You may obtain a copy of the License at
     10 
     11         http://www.apache.org/licenses/LICENSE-2.0
     12 
     13     Unless required by applicable law or agreed to in writing, software
     14     distributed under the License is distributed on an "AS IS" BASIS,
     15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16     See the License for the specific language governing permissions and
     17     limitations under the License.
     18 -->
     19 <p>The Android framework has a small tool called <code>validatekeymaps</code> to validate the
     20 syntax of input device configuration files, key layout files, key character
     21 maps files and virtual key definition files.</p>
     22 <h2 id="compilation">Compilation</h2>
     23 <p>To compile <code>validatekeymaps</code>, set up the development environment, download
     24 the Android source tree, compile it, then run:</p>
     25 <pre><code>$ mmm frameworks/base/tools/validatekeymaps
     26 </code></pre>
     27 <p>This command should compile a host tool called validatekeymaps into the
     28 <code>out/host/&amp;lt;os&amp;gt;/bin</code> directory.</p>
     29 <h2 id="usage">Usage</h2>
     30 <p>If you ran <code>envsetup.sh</code> to set up your development environment, then the
     31 <code>validatekeymaps</code> tool should already be on your path.  You can verify
     32 this by running <code>validatekeymaps</code>.</p>
     33 <pre><code>$ validatekeymaps
     34 
     35 Keymap Validation Tool
     36 
     37 Usage:
     38  validatekeymaps [*.kl] [*.kcm] [*.idc] [virtualkeys.*] [...]
     39    Validates the specified key layouts, key character maps, 
     40    input device configurations, or virtual key definitions.
     41 </code></pre>
     42 <p>Then all you need to do is run <code>validatekeymaps</code> an give it the path of
     43 one or more files to validate.</p>
     44 <pre><code>$ validatekeymaps frameworks/base/data/keyboards/Generic.kl
     45 
     46 Validating file 'frameworks/base/data/keyboards/Generic.kl'...
     47 No errors.
     48 
     49 Success.
     50 </code></pre>
     51 <p>And if there is an error...</p>
     52 <pre><code>$ validatekeymaps Bad.kl
     53 
     54 Validating file 'Bad.kl'...
     55 E/KeyLayoutMap(87688): Bad.kl:24: Expected keyword, got 'ke'.
     56 Error -22 parsing key layout file.
     57 
     58 Failed!
     59 </code></pre>
     60 <h2 id="automation">Automation</h2>
     61 <p>It is a <em>very</em> good idea to run <code>validatekeymaps</code> on all configuration files
     62 before installing them on a device.</p>
     63 <p>The process can easily be automated as part of the build system by using a
     64 script or a makefile.</p>
     65 <p>The following sample makefile is based on the contents of
     66 <code>frameworks/base/data/keyboards/Android.mk</code>.</p>
     67 <pre><code># This makefile performs build time validation of framework keymap files.
     68 
     69 LOCAL_PATH := $(call my-dir)
     70 
     71 # Validate all key maps.
     72 include $(CLEAR_VARS)
     73 
     74 validatekeymaps := $(HOST_OUT_EXECUTABLES)/validatekeymaps$(HOST_EXECUTABLE_SUFFIX)
     75 files := MyKeyboard.kl MyKeyboard.kcm MyTouchScreen.idc
     76 
     77 LOCAL_MODULE := validate_framework_keymaps
     78 LOCAL_MODULE_TAGS := optional
     79 LOCAL_REQUIRED_MODULES := validatekeymaps
     80 
     81 validate_framework_keymaps: $(files)
     82     $(hide) $(validatekeymaps) $(files)
     83 
     84 include $(BUILD_PHONY_PACKAGE)
     85 </code></pre>
     86