External keyboard remapping for Android

本文详细介绍了如何为Android设备配置外置键盘映射,包括理解关键概念、准备必要的工具、获取键盘PID/VID、编辑配置文件以及实现自定义映射,以满足不同语言需求。

最近在研究Android外置键盘mapping的问题,搜到几篇有价值的文章贴上来供参考。

--------------------------------------------------------

Disclaimer

This short tutorial is based on my own  research  regarding missing keyboard layout mapping in stock Honeycomb/ICS Android for my Motorola XOOM. It is not intended to be a complete description of the Android input system, please refer to the official documentation for more information. This text should suffice for anyone with a basic knowledge about IT :P Anyway, if you break something, 'aint my fault. Won't take any responsibilities for YOUR actions.

Requirements
- rooted Android 3.0+ device (3.0, 3.1, 3.2, 4.0)
- text editor
- external keyboard to play with 

Background stuff
(simplified, no bashing :P)
Keyboard (connected to any device) sends key codes to the target device. Key codes are just plain numbers, eg. if you press the "A" key on the keyboard, the computer reads "30" number. Since "30" is quite difficult to remember as being the "A" button, it is much more handy to describe keycodes as char codes: in the target software we get a KEY_A instead of 30.

Android uses two files for keyboard key-to-output mapping: .kl (key layout) and .kcm (key character map).
*.kl file describes the mapping between real keyboard codes to their virtual values, eg. 30 => KEY_A.
*.kcm file converts char codes to key events (KEY_A pressed? Send character "a". Shift + KEY_A? Send character "A", etc.)

So if you connect an external keyboard (USB, BT, Ir?) to your Android device, you get the following chain:
Code:
[keyboard] => [kl] => [kcm] => [application]
All devices (well, most of them) can be identified by VID (Vendor ID) and PID (product ID). VID and PID are 4 hex symbols each.

Android by default uses /system/usr/keylayout/Generic.kl and /system/usr/keychars/Generic.kcm for keyboard handling. If you look into /system/usr/keylayout/ and /system/usr/keychars/ you may find some more keymaps, including something like Vendor_xxxx_Product_xxxx.* Those files are used for specific devices, eg. Vendor_045e_Product_028e.kl is used for XBox 360 controller. When you connect the keyboard, Android checks the peripherial device VID and PID and looks for matching kl and/or kcm. If there is no matching file found, Generic.kl/Generic.kcm   is used instead (disjoint -> you may have a specific kl and generic kcm, generic kl and specific kcm, etc.).
You may get the PID/VID of your external keyboard under for example Windows (in device manager [devmgmt.msc] find your keyboard and check its details [properties->details], for example HID\VID_046D&PID_C312\6&26DA469B&0&0000 => Vendor_046d_Product_C312). So if you would like to prepare a keymap for my USB Logitech keyboard, you will have to provide me with Vendor_046d_Product_C312.[kl|kcm] files 

Both KCM and KL files are encoded in ANSI -> no special (national) characters allowed except for 'classic' set! If you want to include any national or extra character, you need to use their unicode hex values in \uXXXX variant. See http://www.tamasoft.co.jp/en/general-info/unicode.html  for a huge list of unicode characters.

Getting hands dirty
- pull Generic.kcm from your device via adb:
Code:
adb pull /system/usr/keychars/Generic.kcm
- open it with Notepad++
- scroll through the blahblah about not modifying the file to the section with
Code:
key A {
    label:                              'A'
- this is where your work starts!

In general the map is composed as fillows:
Code:
# comment starts with a hash
key [keycode] {
    label:                 '[label]'
    base:                  '[key without any modifiers]'
    [modifier]:            '[key with modifier]'
    [modifier]+[modifier]: '[key with both modifiers]'
    [modifier],[modifier]: '[key with any of listed modifiers]'
    [modifier]:            fallback [magic key] # read below
    [modifier],[modifier]: none
}
Modifiers can be: ralt, lalt, alt (right/left ALT, any ALT), rshift, lshift, shift (right/left SHIFT, any SHIFT), rctrl, lctrl, ctrl (left/right CTRL, any CTRL), capslock (no right CAPSLOCK on the kb, sorry   ), rmeta, lmeta, meta (right/left WIN key, any WIN key). There are probably more, but didn't encounter any...

So, let's make the A key work like on Polish (Programmer) keyboard layout (namely a, A, ą, Ą letters):
Code:
key A {
    label:                              'A'
    base:                               'a'
    shift, capslock:                    'A'
    ralt:                               '\u0105'
    shift+ralt, capslock+ralt:          '\u0104'
    lalt, meta:                         none  # ctrl omitted - ctrl+a does something...
}
Polish letters "ą" and "Ą" have their unicode values of 0x0105 and 0x0104 respectively, thus in order to have them available via right alt + A, we use ralt modifier and shift/capslock ralt modifier. Please note, that it is necessary to have 'shift' modifier for capital A.

Code:
fallback magic key
is used to map certain key combinations to other commands ("hardware buttons"), such as HOME, SEARCH, MENU, APP_SWITCH, etc. Thus if for example you would like to have lalt+tab for app switching you would have to use the following:
Code:
key TAB {
    label:                              '\t'
    base:                               '\t'
    lalt:                               fallback APP_SWITCH # alt + tab :)
    ralt, meta:                   none
}
And now a Windows+D for desktop shortcut:
Code:
key D {
    label:                              'D'
    base:                               'd'
    shift, capslock:                    'D'
    meta:                               fallback HOME # show desktop
    alt:                              none
}
In short
- in most cases the Generic.kl file is ok, there is no need to prepare .kl for a common keyboard
- either edit Generic.kcm or get VID/PID of your keyboard and prepare a key layout for your language and push it to /system/usr/keychars/

Hints
- backup your Generic.kcm file!
- try to be as specific as possible   if you do not use a combination, map it into 'none' section; when you map ralt, don't include alt in 'none', include lalt instead. Remember, that some key combinations have special meanings (ctrl+d, ctrl+c, ctrl+v, etc), and it is better not to include them in your map.
- backup your layout - I lost a lot of time re-creating my keymap after ROM upgrade (symbolic link is a better idea!)
- look through the entire Generic.kcm file - there are a lot of fancy key combinations, for example ESCAPE key can !by default! handle MENU, BACK and HOME keys!
- possible fallback keys are listed in .kl file
- use logcat! You can spot information about external input device and a note about applied KCM/KL files

Finally

Hit "thanks" if you find it helpful. If you prepare a good (national) key layout, please share it!


From: http://forum.xda-developers.com/showthread.php?t=1568760


标题基于Python的汽车之家网站舆情分析系统研究AI更换标题第1章引言阐述汽车之家网站舆情分析的研究背景、意义、国内外研究现状、论文方法及创新点。1.1研究背景与意义说明汽车之家网站舆情分析对汽车行业及消费者的重要性。1.2国内外研究现状概述国内外在汽车舆情分析领域的研究进展与成果。1.3论文方法及创新点介绍本文采用的研究方法及相较于前人的创新之处。第2章相关理论总结和评述舆情分析、Python编程及网络爬虫相关理论。2.1舆情分析理论阐述舆情分析的基本概念、流程及关键技术。2.2Python编程基础介绍Python语言特点及其在数据分析中的应用。2.3网络爬虫技术说明网络爬虫的原理及在舆情数据收集中的应用。第3章系统设计详细描述基于Python的汽车之家网站舆情分析系统的设计方案。3.1系统架构设计给出系统的整体架构,包括数据收集、处理、分析及展示模块。3.2数据收集模块设计介绍如何利用网络爬虫技术收集汽车之家网站的舆情数据。3.3数据处理与分析模块设计阐述数据处理流程及舆情分析算法的选择与实现。第4章系统实现与测试介绍系统的实现过程及测试方法,确保系统稳定可靠。4.1系统实现环境列出系统实现所需的软件、硬件环境及开发工具。4.2系统实现过程详细描述系统各模块的实现步骤及代码实现细节。4.3系统测试方法介绍系统测试的方法、测试用例及测试结果分析。第5章研究结果与分析呈现系统运行结果,分析舆情数据,提出见解。5.1舆情数据可视化展示通过图表等形式展示舆情数据的分布、趋势等特征。5.2舆情分析结果解读对舆情分析结果进行解读,提出对汽车行业的见解。5.3对比方法分析将本系统与其他舆情分析系统进行对比,分析优劣。第6章结论与展望总结研究成果,提出未来研究方向。6.1研究结论概括本文的主要研究成果及对汽车之家网站舆情分析的贡献。6.2展望指出系统存在的不足及未来改进方向,展望舆情
【磁场】扩展卡尔曼滤波器用于利用高斯过程回归进行磁场SLAM研究(Matlab代码实现)内容概要:本文介绍了利用扩展卡尔曼滤波器(EKF)结合高斯过程回归(GPR)进行磁场辅助的SLAM(同步定位与地图构建)研究,并提供了完整的Matlab代码实现。该方法通过高斯过程回归对磁场空间进行建模,有效捕捉磁场分布的非线性特征,同时利用扩展卡尔曼滤波器融合传感器数据,实现移动机器人在复杂环境中的精确定位与地图构建。研究重点在于提升室内等无GPS环境下定位系统的精度与鲁棒性,尤其适用于磁场特征明显的场景。文中详细阐述了算法原理、数学模型构建、状态估计流程及仿真实验设计。; 适合人群:具备一定Matlab编程基础,熟悉机器人感知、导航或状态估计相关理论的研究生、科研人员及从事SLAM算法开发的工程师。; 使用场景及目标:①应用于室内机器人、AGV等在缺乏GPS信号环境下的高精度定位与地图构建;②为磁场SLAM系统的设计与优化提供算法参考和技术验证平台;③帮助研究人员深入理解EKF与GPR在非线性系统中的融合机制及实际应用方法。; 阅读建议:建议读者结合Matlab代码逐模块分析算法实现细节,重点关注高斯过程回归的训练与预测过程以及EKF的状态更新逻辑,可通过替换实际磁场数据进行实验验证,进一步拓展至多源传感器融合场景。
<think>好的,用户想了解行重映射的概念和实现方法。首先,我需要明确什么是行重映射。根据字面意思,可能是指对数据结构中的行进行重新排列或映射的操作。这在编程中常见于数据处理、矩阵操作或内存管理等领域。 接下来,我应该从概念入手。行重映射可能涉及改变数据行的顺序,比如矩阵的行交换,或者根据某种规则重新排列数据表中的行。例如,在图像处理中,像素行的翻转;在数据库中对查询结果进行排序或分页。 然后,考虑实现方法。常见的实现可能包括使用索引数组来记录新的行顺序,或者通过函数映射来生成新的行排列。例如,创建一个索引数组,其中每个元素表示原数据行的新位置,然后根据这个数组重新构建数据。此外,可能需要考虑性能优化,特别是处理大规模数据时,避免不必要的复制操作,使用原地算法或指针操作。 还需要结合用户提供的引用内容,虽然引用内容中的代码片段似乎涉及多线程同步、枚举类型处理和构建配置,但可能与行重映射的底层实现有关联。例如,引用[1]提到的clFinish用于同步命令队列,可能在并行处理行重映射时确保所有操作完成;引用[2]和[3]提到的代码生成和构建配置,可能在自动生成行重映射代码或优化生产环境下的处理流程中有参考价值。 用户可能需要具体的例子来理解。比如,在C语言中,可以通过指针数组来重映射矩阵的行,避免复制整个行数据。在Python中,可以使用列表推导式或NumPy的高级索引来实现。此外,内存映射文件或GPU加速也可能用于大规模数据处理,引用[1]中的OpenCL命令队列管理可能与此相关。 最后,需要生成相关问题,帮助用户深入理解。例如,如何优化行重映射的性能?行重映射在图像处理中的具体应用?如何处理动态变化的重映射规则?这些问题可以引导用户进一步探索实际应用中的挑战和解决方案。</think>### 行重映射的概念与实现 #### 一、行重映射概念 行重映射(Row Remapping)指在数据结构(如矩阵、数组、数据库表)中,通过特定规则重新排列行的逻辑或物理顺序。其核心目标包括: 1. **数据重组**:根据索引、哈希函数或排序规则重新组织行 2. **性能优化**:改善内存访问模式(如缓存友好性)[^1] 3. **功能实现**:支持分页、动态过滤、数据加密等场景 典型应用场景: - GPU纹理内存优化中的行对齐(引用OpenCL内存模型) - 数据库查询结果的分页显示 - 矩阵转置运算中的行/列转换 #### 二、实现方法 ##### 1. 索引映射法(最常用) ```cpp // C++示例:通过索引数组实现行重映射 std::vector<int> remap_index = {2, 0, 1}; // 新行顺序 std::vector<Row> original_data = {row0, row1, row2}; std::vector<Row> remapped_data; for (auto& idx : remap_index) { remapped_data.push_back(original_data[idx]); } ``` ##### 2. 函数映射法 ```python # Python示例:使用lambda函数定义映射规则 remap_func = lambda x: x % 3 # 将行按模3分组 remapped_rows = [[] for _ in range(3)] for idx, row in enumerate(data_matrix): remapped_rows[remap_func(idx)].append(row) ``` ##### 3. 硬件加速实现(引用GPU编程思想[^1]) ```opencl __kernel void row_remap(__global float* src, __global float* dest, __constant int* index_map) { int new_row = get_global_id(0); int old_row = index_map[new_row]; // 拷贝整行数据 for(int col=0; col<COL_SIZE; col++) { dest[new_row*COL_SIZE + col] = src[old_row*COL_SIZE + col]; } } ``` #### 三、关键技术考量 1. **内存管理** - 原地操作 vs 新建内存空间 - 缓存预取优化(引用内存访问模式优化) 2. **动态更新** ```java // Java示例:动态更新映射规则 ConcurrentHashMap<Integer, Integer> liveRemap = new ConcurrentHashMap<>(); // 线程安全地更新映射关系 liveRemap.put(newRow, oldRow); ``` 3. **性能优化** - SIMD指令加速批量数据移动 - 惰性求值(Lazy Evaluation)技术
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值