views:

399

answers:

3

I am attempting to utilize a hardware button on my Motorola MC75 to perform the function of a button event that I created on the form. I have attempted to use the WindowsCE.Forms.HardwareButton class, however, I can't seem to get it working. I can't even capture any KeyDown event on the form. I set up the event and the KeyPreview is set to true on the form, however, the event is never fired on any hardware button I press on the device while debugging.

Any suggestions?

Thanks in advance.

A: 

Hardware button control is usually device-specific. Motorola/Symbal have an SDK for their devices, but I wasn't able to find a link to it. Normally, there will be a manufacturer-specific DLL on the devices that you would PInvoke into in order to read and control the hardware buttons.

MusiGenesis
A: 

They have the EMDK for .NET 2.2, however, I don't see any way to capture their buttons. I've added the KeyDown event and can captre most of the buttons, but not all of them. Any idea why?

Bob Manz
A: 

There is a native function to forward all keys to your application.

[DllImport("coredll.dll", SetLastError = true)]
static extern bool AllKeys(bool bAllKeys);

See this MSDN blog for a C++ example. You can receive KeyDown and KeyUp events on a Windows Form using AllKeys. It works on any Windows Mobile 2003 - current device.

Trevor Balcom
Hmm, that got almost all the keys to be captured on the KeyDown event, however, it still didn't get the 2 keys I wanted. These are yellow buttons on the side of the device. Any idea?
Bob Manz
Is the scanner wedge program running? Try closing the scanner wedge program and then see if you get the KeyDown event for the yellow scanner buttons. Another option is to use SetWindowsHookEx (undocumented). There are plenty of examples on Google. I have seen SetWindowsHookEx fail on some devices if there is already another program running a hook. In most cases, the scanner wedge program is the program with the other hook open.
Trevor Balcom