How to customize the keyboard write driver for WinCE

Source: Internet
Author: User
Tags printable characters

I often see people asking how to create drivers for custom keyboards. Here I will talk about my experience. How to write the complete keyboard driver is not the purpose of this article, which is detailed on msdn. Here we will talk about how to change the value of the SHIFT + 2 output symbol @ on the standard American English keyboard to the euro symbol? Or how do you create a French keyboard? Or you want to design the keyboard based on the same hardware. The software also supports layout in English, French, and Russian. How can this problem be solved?

From the perspective of the keyboard driver, the response process of the keyboard driver to the button action can be described as follows:

  1. Key interruption
  2. Scan code of the keyboard driver's read button
  3. The keyboard driver maps scan code to virtual key and Unicode characters.
  4. The keyboard driver sends the key message to the graphic window subsystem (GWES ).

The scan code of the key is determined by the keyboard matrix, which is related to the hardware design of the keyboard. Therefore, from the software perspective, the scan code of the keyboard cannot be changed. However, because the key outputs printable characters or virtual keys, there is a ing between them. This ing can be specified by the keyboard driver or even dynamically switched. The standard keyboard driver framework of Wince defines two ing tables: The device layout table from scan code to virtual key, and the input language table from virtual key to Unicode ). By modifying the definitions of the two ing tables, we can control the output of each key or key combination on the keyboard.

D: \ wince500 \ public \ common \ oak \ drivers \ keybd directory contains some source code for the standard keyboard: the scan code to virtual key ing table is in the devicelayouts subdirectory, the inputlangs subdirectory is a unicode ing table from virtual key to Unicode. Specifically, the two tables are modified, and some other auxiliary code is compiled into DLL. In addition, WinCE also provides a tool (D: \ wince500 \ public \ common \ oak \ bin \ i386 \ kbdgen.exe) to extract the ing table from the keyboard driver of Windows XP. For example, the following command generates the source code of the French keyboard ing table:

Kbdgen.exe kbdfr. dll-O kbd_040c-I 0000040c

The output result contains three files:

Kbd_040c.reg: Registry File
Kbd_040cdl.cpp: Scan code-> virtual key ing table
Kbd_040cil.cpp: Virtual key-> wide character ing table

The keyboard driver name can be found in [HKEY_LOCAL_MACHINE \ SYSTEM \ controlset001 \ Control \ keyboard layouts] in the registry. For example, if the locale in French is 040c, the driver kbdfr can be found under the 0000040c subkey. DLL.

Scan code to virtual key (device layout) defined in the scancodetovkeytable array, generally do not need to change:

# Define scancodetablefirst 0x00
# Define scancodetablelast 0x8f
Static uint8 scancodetovkeytable [] =
{
0, // scan code 0x0
Vk_f9, // scan code 0x1
0, // scan code 0x2
Vk_f5, // scan code 0x3
Vk_f3, // scan code 0x4
Vk_f1, // scan code 0x5
Vk_f2, // scan code 0x6
Vk_f12, // scan code 0x7
0, // scan code 0x8
Vk_f10, // scan code 0x9
Vk_f8, // scan code 0xa
Vk_f6, // scan code 0xb

};

Sometimes you may want to know the scan code corresponding to each key on the keyboard. You can use retailmsg to print the scan code in the keybdpdd_geteventex2 function of the keyboard drive.

The focus of customization is to modify the virtual key to the Unicode ing table, that is, avktowelist ~ Avktowch5 and other arrays. The European language keyboard also needs to change the adeadkey array. These arrays control the output of various combinations of buttons, such as pressing a, Shift + A, CTRL + Shift +, dead key + A, which outputs something respectively.

For example, Shift + 2 output @ on the standard American keyboard. You want to change it to the euro symbol €. First, check that the Unicode value of € is 20ac (using the symbol dialog box of MS Office), and then modify the avktowch2 array:

Static vk_to_wchars2 avktowch2 [] = {
{'2', 0, '2', 0x20ac },

};

If you want CTRL + ALT + 2 to output § (UNICODE 00a7) at the same time, change avktowch5 instead of avktowch2:

Static vk_to_wchars5 avktowch5 [] = {
{'2', 0, '2', 0x20ac, wch_none, 0x0000, 0xb9 },

};

 

The modification process of the ing table is roughly the same. With DLL, you need to make some configuration in the registry. Add the following in platform. Reg:

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ layouts \ 0000040c]
"Layout file" = "kbd_040c.dll"
"Layout text" = "French"
"Ps2_at" = "kbd_040c.dll"

If you support both English and French keyboards, you can set French as the second keyboard:
[HKEY_CURRENT_USER \ keyboard layout \ preload \ 2]
@ = "0000040c"

You can even set the hotkey to switch the keyboard at runtime:
; Enabling Alt + shift keyboard layout toggle short cut key
; "Hotkey" = "1" => Alt + Shift
; "Hotkey" = "2" => Ctrl + Shift
; "Hotkey" = "3" => none
; The toggle key is disabled even if the key is not defined.
[HKEY_CURRENT_USER \ keyboard layout \ toggle]
"Hotkey" = "1"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.