HardwareButton Class doesn't work - red and green telefon buttons

G

Guest

Hi,

I am trying to get access to the red and green phoen buttons. I thought that
the HardwareButton class would do the job. I am trying my code in the
emulator and on a device but this doesn't work as I expected.

I am using CF 2.0 SP1 beta on WM5.0.

On my device I can catch Appkey 1 - 4 (calender, contacts, camera,
recorder), but not the red and green buttons.

Using the WIndows Mobile 5.0 Pocket PC Phone emulator I can only catch
Appkey 2 which is the calender button.

The buttons on the left and right side return no Appkey values:

left top: e.KeyCode RButton | MButton | Space

left bottom: e.KeyCode Back | Space

on the right: 121

The other buttons I cannot catch (contacts, red, green)


Here is some code:

private void HBConfig()

{

int j;

j = 0;

try

{

HardwareKeys hk = HardwareKeys.ApplicationKey1;

for (int i = 0; i < 6; i++)

{

j = i;

hwb = new HardwareButton();

hwb.AssociatedControl = this;

hwb.HardwareKey = hk + i;

}

}

catch (Exception exc)

{

MessageBox.Show(exc.Message + " Check if the hardware " +

"button is physically available on this device. Stopped at "+(j+1));

}

}



private void ButtonKeyDown(object sender, KeyEventArgs e)

{

for(int i=0;i<6;i++)

{

if(((HardwareKeys)e.KeyCode) == hwb.HardwareKey)

break;

}

switch (e.KeyCode)

{


......





What is going wrong?

How can I catch the red and green telefon button ?
 
G

Guest

The HardwareButton class is for buttons common to all WM devices, not custom
buttons (which these fall into). Add to that the fact that phones must
*always* be capable of being a phone for emergency calling so the ability to
override these buttons would be a rarity (and possibly a liability).

-Chris
 
G

Guest

I don't think they post to the keyboard. My bet is that they are pure GPIOs
that create interrupts handled at the OS level and there's no way to
intercept them without either a BSP or some serious inside knowledge. I
wouldn't bother trying this as I'd consider it too difficult, and this is
coming from someone who tries to write drivers in managed code.

-Chris
 
G

Guest

Well I did a search in the samples the SDK installed and there is a sample
that uses the green and red buttons: Donuts2. This is a cpp game sample that
uses the green button to switch audio on/off and the red button to quit.

This samples uses a set of keyboard functions: LoadAccelerators.

Looks like I will have to spend more time here ...
 
G

Guest

Hi Alex and Chris,

did it this working in the end. I first thought about the accerator stuf -
but this didn't appear to be right so I looked around a bit and came up with
"Keyboard hook in the CF v2":
http://blog.opennetcf.org/ayakhnin/PermaLink.aspx?guid=84b95802-76d7-499c-b266-e2251ab15706.

That might have worked - but seamed quite a task and then what happens if
another task eats the keys?

A longer search here brought up "Application using Hardware buttons in
pocketpc.developer" byNeil Wallace. Thanks Neil, this liite sample got me
right.

With the undocumented call:
private static extern bool UnregisterFunc1(KeyModifiers modifiers,
KeysHardware key);
I can switch off any other task that is using the key and with:

private static extern bool RegisterHotKey(IntPtr hWnd, KeysHardware id,
KeyModifiers modifiers, KeysHardware key);

get my task to recieve the WM_HOTKEY messages!

This even works system wide!

Neil, thanks again!

PWF
 
E

Elton

Hi PWF,

can you tell me the address of the page written by Neil Wallace? I would
love to take a look.

Actually I am using the code from some other site, which use the
UnregisterFunc1 call and receive WM_HOTKEY and I got it works. But what I
really want to do is to trap the left, right softbutton introduce by WM5 and
the red, green phone button.

Do u know the keycode to trap them?

Elton
 
G

Guest

Hi Elton,

try this:
public enum KeysHardware : int
{
VK_F1 = 0x70,
VK_F2 = 0x71,
VK_F3 = 0x72,
VK_F4 = 0x73,
VK_F5 = 0x74,
VK_F6 = 0x75,
VK_F7 = 0x76,
VK_F8 = 0x77,
VK_F9 = 0x78,
VK_F10 = 0x79,
VK_F11 = 0x7A,
VK_F12 = 0x7B,
VK_TSOFT1 = VK_F1, // Softkey 1
VK_TSOFT2 = VK_F2, // Softkey 2
VK_TTALK = VK_F3, // Talk = Green Phone Button
VK_TEND = VK_F4, // End = Red Phone Button
VK_APP1 = 0xC1, // upto 6 other hardware buttons
VK_APP2 = 0xC2,
VK_APP3 = 0xC3,
VK_APP4 = 0xC4,
VK_APP5 = 0xC5,
VK_APP6 = 0xC6,

RedPhoneButton = VK_TEND,
GreenPhoneButton = VK_TTALK
}

Neil posted in microsoft.public.pocketpc.developer.
The link is:
http://msdn.microsoft.com/newsgroup...&p=1&tid=50bce0b4-670a-4e06-b86c-a8438e0aab6d

This is where I got the UnregisterFunc1 and RegisterHotkey calls from.


Let me know if the soft menus can be used as hotkeys!



Have fun!

PWF
 
E

Elton

Dear PWF,

I have just tried the code you posted, all the hardware buttons work!
However, there is one draw back. Unlike other buttons, the 4 special
buttons: green, red phone and left, right softbuttons will not function
after the program exit. it looks like the relationship between the system
and special keys have beenn cut off. Do u know how to restore the orginial
functions of these special buttons?

Elton
 
G

Guest

Hi Elton,

I have had the same experiance. The UnregisterFunc1 call seems to unregister
the current application that is exclusively handling the hardware button as a
hotkey, allowing our own apps to use the buttons.

The only way I have found to restore the previous application's hotkey is to
perform a soft reset.

I have not been able to find another way of getting access to the special
buttons. The advantage is of course that the hotkeys work system wide.

BTW: what application are you writing?
I am writing a new dialer program as I was not at all pleased with
Microsofts attempt. I find the speed dial buttons don't really help in
everyday life, so I wrote my own.

PWF.
 
E

Elton

I am working on a game so I don't really need system wide access.
and since it is just a game, I don't think soft reset after every game play
is acceptable for end user.
I suggest I have to dig some where else.:<

Elton
 
G

Guest

Hi Elton,

have a look at the SDK samples. There is a game sample called Donuts that
uses the special buttons.

This is a cpp game sample that
uses the green button to switch audio on/off and the red button to quit.
After the game finishes the buttons take their previous functions!

Regards,
Paul
 
E

Elton

i am not very good at c++ but then i will see what i can get from the sample
game.
SDK? smartdevice SDK comes with vs2003/5? i am using vs2005 now, didn't
install any SDK myself.

Elton
 
E

Elton

Dear Paul,

The Donut sample use Hook to get the system message. it is not the same as
what we are doing.
Too bad.

Elton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top