Use HardwareButton to operate the hardware buttons of Windows Mobile

Use HardwareButton to operate the hardware buttons of Windows Mobile

    As you all know, in the Windows Mobile application, we can use the analog button VK to simulate the functions of some hardware buttons, such as calling the today’s screen, locking the keyboard, turning off the device, turning on the speaker, etc. (For details, please refer to Huang Jidong’s post: talk more Simulate key operation on Windows Mobile ). In some cases, we need to know which hardware button the user pressed and rewrite the function of the hardware button (such as a game program). The hardware button corresponds to a specific value, we can use this value to judge. In .NET CF, the HardwareButton class allows to override the functions of the Pocket PC hardware buttons.

    1. we need to add a reference to the middle of the naming "Microsoft.WindowsCE.Forms" in the application.

    Then, create an instance of HardwareButton.

hwb1 = new HardwareButton(); hwb2 = new HardwareButton(); ……

    Next, set the AssociatedControl property to the form or control to be activated.

hwb1.AssociatedControl = this; hwb2.AssociatedControl = this; ……

    Finally, set the HardwareKey property to one of the HardwareKeys enumeration values. Up to six hardware buttons can be configured.

hwb1.HardwareKey = HardwareKeys.ApplicationKey1; hwb2.HardwareKey = HardwareKeys.ApplicationKey2; ……

    At the same time, in the OnKeyUp event function of the form, add the processing of the corresponding button,

private void OnKeyUp(object sender, KeyEventArgs e) {switch ((HardwareKeys)e.KeyCode) {case HardwareKeys.ApplicationKey1: statusBar1.Text = "Button 1 pressed."; …… break; case HardwareKeys.ApplicationKey2: statusBar1.Text = "Button 2 pressed."; …… break; default: break;}}

    have to be aware of is:

    1. The number of hardware buttons on some Pocket PCs is not six. And the operating system does not support all buttons. Windows Mobile 2003 for Pocket PC supports four buttons, while Windows Mobile version 5.0 software for Pocket PC supports five buttons.

2. Smartphone and other non-Pocket PC Windows CE devices do not support this type.

Test Results

Tested in WM6.0 Professional Emulator, the specific values ​​obtained are as follows:

    -

The "left, right, up, down, buttons" are 37, 38, 39, 40 

    -

"Enter" is 13

    -

"Left up and down keys" are 38, 40

    -

"Right button" is 121

    -

"Dial button" is 114

    -

"End Button" is 115

Tested in Cingular8125 (WM6.0 Professional), the specific values ​​obtained are as follows:

    -

The "left, right, up, down, buttons" are 37, 38, 39, 40 

    -

"Enter" is 13

    -

"Wireless Management Key" is 198

    -

"Information Management Key" is 193

    -

"Internet Key" is 194

    -

"Dial button" is 114

    -

"End Button" is 115

    -

"Voice Button" is 196

    -

"Camera button" is 195

    The above are my test results, I hope it will be useful to everyone.

Reference: https://cloud.tencent.com/developer/article/1017759 Use HardwareButton to operate Windows Mobile hardware buttons-Cloud + Community-Tencent Cloud