How to Create a Customized Keylayout for Any USB or Bluetooth Keyboard (ROOTED)

本文详细介绍了如何为任意USB或蓝牙键盘创建自定义布局的步骤,需要设备已ROOT权限。教程以dalepl的Thrive10.1英寸002OOM Rooted rom为例进行说明。

How to Create a Customized Keylayout for Any USB or Bluetooth Keyboard (ROOTED)

This tutorial describes how to create a customized keylayout for any USB or Bluetooth keyboard. You will need to be rooted to be able to do this. These instructions were developed using dalepl's Thrive 10.1 inch 002 OOM Rooted rom. 

If you don't understand these instructions or don't feel comfortable doing them, DON'T DO IT. I only represent that they work on my Thrive. As with any such tutorial, 
I AM NOT RESPONSIBLE FOR ANY DAMAGE OR LOSS THAT MAY RESULT FROM ATTEMPTING TO FOLLOW THIS TUTORIAL. USE AT YOUR OWN RISK.
Some settling may occur. Objects may be closer than they appear. Do not eat. 

Basically the procedure is as follows:
  1. Copy /system/usr/keylayout/Generic.kl to /system/usr/keylayout/Vendor_<vendorID>_Product_<productID>.kl where <vendorID> and <productID> are the four digit hex IDs of your keyboard.

  2. Edit Vendor_<vendorID>_Product_<productID>.kl to assign the desired key actions to the scancodes of the keys you want to modify.
Searching the net, you may find the suggestion of editing  Generic.kl or  qwerty.kl directly. I do not recommend this.  qwerty.kl is no longer used. Generic.kl is used for anything that does not have a specific keylayout, so any changes you make to it will apply to all keyboards and if you mess it up you can make your Thrive fail to respond properly to any keyboard input

DETERMINING THE KEYBOARD'S VENDOR AND PRODUCT ID

In an ADB shell or terminal emulator:
Code:
   sh-4.1# cat /proc/bus/input/devices
   ...
   I: Bus=0005 Vendor=099a Product=0540 Version=011b
   N: Name="Bluetooth Keyboard"
   P: Phys=E0:B9:A5:A0:9F:DE
   S: Sysfs=/devices/virtual/bluetooth/hci0/hci0:12/input7
   U: Uniq=00:18:A3:03:0C:A3
   H: Handlers=sysrq event7
   B: EV=12001b
   B: KEY=10000 2000007 ff9f387a d94157ff febeffdf ffefffff ffffffff fffffffe
   B: ABS=f00 0
   B: MSC=10
   B: LED=1f
find the entry for your keyboard, and note the Vendor and Product IDs. This example is from my Azio mini-bluetooth keyboard, the vendorID is 099a and the productID is 0540.

The  dmesg command can also be used. The format in the keyboard's entry is:
bbbb:vvvv:pppp:rrrr
where:
bbbb is the Bus
vvvv is the VendorID
pppp is the ProductID
rrrr is the Version

For USB keyboards, the  lsusb command can also be used. This will show an entry for each attached USB device, including the internal ones, so compare the list before and after attaching the USB keyboard. The format for this entry is:
Bus bbb Device ddd: ID vvvv:pppp

DETERMINING THE SCANCODE OF THE DESIRED KEYS
Download the  KeyTest.apk from:
https://github.com/chrisboyle/keytest/downloads
and sideload it into your Thrive. I know of no other way to reliably identify the scancodes of the keys of interest on an arbitrary keyboard. If you don't want to install this, I can understand, but you will have to identify the desired scancodes in some other way.

To sideload the KeyTest apk:
  1. Ensure that Settings/Applications/Development/Unknown sources is checked
  2. Copy KeyTest.apk to your Thrive in a location that you can access from the File Manager. I had to disable Settings/Applications/Development/USB Debugging to get the Thrive to show up as My Computer/AT100 in Windows(tm) Explorer. I also could not copy KeyTest.apk to the top level of either Internal Storage or SD Card, so in Windows(TM) Explorer I created the directory My Computer/AT100/Internal Storage/MyApps, and copied KeyTest.apk there.
  3. On your Thrive, in File Manager, locate KeyTest.apk and tap on it.
  4. Select Install on the Package installer dialog that appears.
Attach your keyboard and run the KeyTest app.
Press the keys you desire to modify, and note the scancode that the app reports for each. You want the scancode value, not the keycode value.

MODIFYING THE KEYLAYOUT FILE
Android is based on Linux, which is derived from Unix. Linux and MS Windows(tm) use different conventions as to what constitutes the end of a line. If you edit your new keylayout file in MS Windows(tm), you will need to use an editor that can handle Unix formatted files. Notepad will NOT work. I use PsPad ( editor PSPad - freeware HTML editor, PHP editor, XHTML, JavaScript, ASP, Perl, C, HEX editor), although there are many others that are suitable. With the keylayout file open in PsPad, look at the status bar at the bottom of the window. It should say UNIX just to the left of the Code page: notice. If it says DOS or MAC, click on the mode name until it says UNIX

This link:
Key Layout Files | Android Open Source
describes the syntax of a keylayout file and the meaning of the modifiers. The syntax is basically:

key <scancode> <Android key> <modifier>

where <scancode> is the scancode returned by the KeyTest app. Examine your copy of the  Generic.kl to get some idea of the Android keys that are available. A list of them and their meanings can be found here, although this list does not entirely agree with what is in the 3.2.1  Generic.kl, and so may be somewhat outdated:
KeyEvent | Android Developers
You will need to scroll down a ways.

For my desktop PS/2 keyboard, connected through an IO Gear PS2-USB adapter, I wanted to put Back on the left Windows(tm) key (scancode 125), Home on the right Windows(tm) key (126), and Menu on the Menu key (127). It turns out that the Menu key is already configured for the Android menu function, but the two Windows(tm) keys needed modification. I adjusted the keymap as follows:

key 125 BACK WAKE_DROPPED 
key 126 HOME WAKE_DROPPED
key 127 MENU WAKE_DROPPED 

My Azio mini-bluetooth keyboard does not have a right Windows(tm) key, so I put Home on the right alt key instead:

key 125 BACK WAKE_DROPPED 
key 100 HOME WAKE_DROPPED
key 127 MENU WAKE_DROPPED 

Note: the Android key that represents the traditional home action of "move to the begining of the line" is called MOVE_HOME.

On my Azio mini-bluetooth keyboard, with dalepl's 002 OOM rom and the stock media player, the keys that map to MEDIA_PLAY_PAUSE, MEDIA_NEXT, and MEDIA_PREVIOUS work, while VOLUME_MUTE, VOLUME_UP, and VOLUME_DOWN appear to have no effect, although some other media player might respond to them.

USING ADB TO DO THIS
My preferred way to create and install a custom keymap is to use ADB (Android Debug Bridge) to pull the files to my PC and edit them there.

You need to have ADB set up and working such that issuing the command:
Code:
   E:\Thrive>adb devices
   List of devices attached
   2804049441f8057 device
works. See this forum's ADB Drivers thread:  [Drivers] USB ADB Driver Installation Package for information on setting up ADB. I have my PC set up so that the adb command's directory is in my path environment variable. That way I can run adb commands from any directory that I happen to be in. If you don't know how to do this on your system, you probably should not mess with it, since screwing up the path environment variable can cause a lot of things to not work. Simply open your Command Prompt window in a directory where the adb command will work.

When using ADB, there are two contexts you need to be aware of, the command prompt and the ADB shell. The command prompt is the level you are in when you open a Command Prompt window. Commands that you enter at this level are executed on your local PC, although they may have actions that affect the attached Thrive. The ADB shell is entered from the command prompt level as follows:
Code:
   E:\Thrive>adb shell
   sh-4.1# <shell commands>
   sh-4.1# exit
   exit
   E:\Thrive>
Note that while you are in the ADB shell, the prompt changes from "E:\Thrive>" (the current directory on the local PC) to "sh-4.1#". You exit the ADB shell and return to the command prompt level by entering the shell command "exit". Commands that you enter in the ADB shell execute on your Thrive.
  1. Retrieve a copy of Generic.kl to your PC. At the command prompt level:
    Code:
       E:\Thrive>adb pull /system/usr/keylayout/Generic.kl
       293 KB/s (9389 bytes in 0.031s)
       E:\Thrive>
  2. On your local PC, copy Generic.kl to Vendor_<vendorID>_Product_<productID>.kl and modify it as desired.

  3. The Thrive's /system partition is normally mounted as read-only. You must remount it as read-write before you can modify its contents. From the command prompt level:
    Code:
       E:\Thrive>adb remount
       remount succeeded
       E:\Thrive>
    On my phone, adb remount does not work, but the method described below under "Doing This Entirely In The Thrive" does, so if this step does not work using ADB, try that method of making the system partition writable.

  4. Upload the modified keylayout to the Thrive. From the command prompt level:
    Code:
       E:Thrive>adb push Vendor_0557_Product_2221.kl /system/usr/keylayout/Vendor_0557_Product_2221.kl
       576 KB/s (9221 bytes in 0.015s)
       E:\Thrive>
  5. Enter the ADB shell, and update the permissions of your new keylayout file:
    Code:
       E:\Thrive>adb shell
       sh-4.1# chmod 644 /system/usr/keylayout/Vendor_0557_Product_2221.kl
       chmod 644 /system/usr/keylayout/Vendor_0557_Product_2221.kl
       sh-4.1# ls -l /system/usr/keylayout
       ls -l /system/usr/keylayout
       -rw-r--r-- root   root   894 2008-08-01 05:00 AVRCP.kl
       -rw-r--r-- root   root   9389 2008-08-01 05:00 Generic.kl
       -rw-r--r-- root   root   1293 2008-08-01 05:00 Vendor_045e_Product_028e.kl
       -rw-r--r-- root   root   1027 2008-08-01 05:00 Vendor_046d_Product_c216.kl
       -rw-r--r-- root   root   1325 2008-08-01 05:00 Vendor_046d_Product_c294.kl
       -rw-r--r-- root   root   1392 2008-08-01 05:00 Vendor_046d_Product_c299.kl
       -rw-r--r-- root   root   2793 2008-08-01 05:00 Vendor_046d_Product_c532.kl
       -rw-r--r-- root   root   1458 2008-08-01 05:00 Vendor_054c_Product_0268.kl
       -rw-r--r-- root   root   9221 2012-03-20 14:18 Vendor_0557_Product_2221.kl
       -rw-r--r-- root   root   2409 2008-08-01 05:00 Vendor_05ac_Product_0239.kl
       -rw-r--r-- root   root   9152 2012-03-15 15:01 Vendor_099a_Product_0540.kl
       -rw-r--r-- root   root   1994 2008-08-01 05:00 Vendor_22b8_Product_093d.kl
       -rw-r--r-- root   root   263 2008-08-01 05:00 gpio-keys.kl
       -rw-r--r-- root   root   2577 2008-08-01 05:00 qwerty.kl
       sh-4.1# exit
       exit
       E:\Thrive>
  6. Shut down and re-boot your Thrive in order to restore the /system partition to its normal read-only state.

DOING THIS ENTIRELY IN THE THRIVE
You will need to install the Terminal Emulator or something equivalent from the Play Store:
https://play.google.com/store/apps/d...al.androidterm
I found that I had to go into preferences and change the font size to 20pt in order to make the text big enough to see.

I also recommend Hacker's Keyboard:
https://play.google.com/store/apps/d...ion.pckeyboard
In order to use the vi editor, you will need a keyboard that supports the <ESC> and directional arrow keys, which the default keyboard does not. You can also use a USB or Bluetooth keyboard, which will allow using the full screen of the Terminal Emulator. In the Hacker's Keyboard settings, I set:
  • Keyboard height, landscape = 40%
  • Keyboard mode, portrait = Full 5-row layout

In the Terminal Emulator:
  1. Become superuser
    Code:
      sh-4.1$ su
      sh-4.1#
  2. Remount the /system partition as read-write
    Code:
       sh-4.1# mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
       sh-4.1#
  3. Change directory to the keylayout directory
    Code:
       sh-4.1# cd /system/usr/keylayout
       sh-4.1#
  4. Make a copy of the Generic keylayout to you new keylayout
    Code:
       sh-4.1# cp Generic.kl Vendor_0557_Product_2221.kl
       sh-4.1#
  5. Edit the new keylayout
    Code:
       sh-4.1# vi Vendor_0557_Product_2221.kl
    The vi editor is not very intuitive and you will need to be familiar with the basics of it before you even try to use it. Teaching vi is well beyond the scope of this tutorial. Googling "vi" will provide a number of useful references.

  6. Shut down and re-boot your Thrive in order to restore the /system partition to its normal read-only state.

You will need to disconnect / unplug your keyboard and reattach it, or shutdown and reboot your Thrive, in order to begin using the new modified keylayout.

REFERENCES
How to map android keys to your usb/bluetooth keyboard - MobileRead Forums
Android keymaps - Chris Boyle

From: http://www.thriveforums.org/forum/toshiba-thrive-development/9626-how-create-customized-keylayout-any-usb-bluetooth-keyboard-rooted.html

<think>好的,用户现在想了解如何在UnrealEngine打包后启用自定义编辑器模式。之前他们问过联邦模拟模式(FedMode)的启用方法,现在转向自定义编辑器模式,需要区分这两个概念。首先,我需要明确自定义编辑器模式通常指的是在编辑器中扩展功能,但用户提到的是打包后的启用,这可能涉及到在打包后的可执行文件中保留或激活某些编辑器功能,这在UE中并不常见,因为打包后的版本通常是去掉编辑器的。接下来,我需要考虑用户可能的真实需求。他们可能在开发一个需要特定工具或模式的应用,希望在打包后的版本中保留这些编辑器功能,比如用于调试或特定用户操作。因此,需要指导如何将自定义编辑器模式编译进游戏可执行文件,并在运行时激活。 步骤方面,首先需要创建自定义的编辑器模块,确保在打包时包含该模块。UE默认在打包时排除编辑器代码,所以必须修改.uproject文件,添加“bBuildEditor”为true。但这样会增加包体大小,可能不符合最佳实践,需要提醒用户注意。 然后,关于启动参数,可能需要通过命令行参数来激活自定义模式,类似于之前的FedMode方法。例如,使用“-EditMode”来触发。同时,需要代码中检查是否处于编辑器环境,并响应命令行参数。 另外,插件依赖也是一个重点,需要确保相关插件如Slate、UnrealEd被包含在打包配置中,否则模块无法加载。用户可能遇到的问题包括模块未正确编译、命令行参数无效、资源加载失败等,需要给出排查建议,比如检查日志、验证插件包含情况。最后,生成的相关问题要围绕自定义编辑器模式的扩展,比如数据保存、多语言支持、性能影响等,帮助用户全面了解后续可能的需求。</think>在Unreal Engine中启用自定义编辑器模式(Customized Editor Mode)并使其在打包后可用,需解决两个核心问题: 1. **保留编辑器功能** 2. **实现模式切换逻辑** ### 一、保留编辑器功能 $$ \text{打包配置满足} \quad bBuildEditor = \text{true} \quad \text{且} \quad bWithEditor = \text{true} $$ 1. 修改`.uproject`文件配置: ```json { "Modules": [ { "Name": "YourProject", "Type": "Runtime", "LoadingPhase": "Default", "AdditionalDependencies": ["UnrealEd"] } ], "TargetPlatforms": ["Win64"], "bBuildEditor": true } ``` - `UnrealEd`依赖确保编辑器代码被编译到可执行文件中[^1] 2. 在`Project Settings > Packaging`中取消勾选`Exclude Editor Content` ### 二、自定义编辑器模式实现 ```cpp // 在YourEditorMode模块中继承FEdMode class FYourCustomEdMode : public FEdMode { virtual void Enter() override { // 激活自定义编辑器的UI和工具 SAssignNew(Widget, SYourEditorWidget); GEditor->GetEditorWorldContext().Window->AddMenuExtension(Widget.ToSharedRef()); } static FName ModeId; }; IMPLEMENT_EDITOR_MODE(FYourCustomEdMode, "YourEdMode"); ``` ### 三、打包后激活模式 通过命令行参数启动编辑器模式: ```bash YourProject.exe -game -edmode=YourEdMode ``` - `-game`参数允许在游戏窗口中嵌入编辑器功能 - 在代码中检查启动参数: ```cpp if (FParse::Param(FCommandLine::Get(), TEXT("edmode"))) { GLevelEditorModeTools().ActivateMode(FYourCustomEdMode::ModeId); } ``` ### 四、关键配置验证 | 配置项 | 预期值 | 验证方法 | |--------|--------|----------| | `bBuildEditor` | true | 检查`.uproject`文件 | | 插件依赖 | `UnrealEd` | 编译日志无缺失符号错误 | | 资源路径 | `/Engine/Editor/...` | 打包后资源存在性检查 | ### 五、常见问题排查 1. **模式未激活** - 检查`DefaultEngine.ini`中是否包含`+EditModes=YourEdMode` 2. **UI元素丢失** - 使用`Slate Widget Reflector`工具调试界面树[^2] 3. **性能下降** - 设置`r.Editor.EnableGameRendering=0`关闭冗余渲染管线
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值