From: Twigg on
Hello i'm trying to handle all the hardware buttons in my .net application.
The device is HTC Touch HD - the buttons are volume up, volume down, maybe
the turn off screen key
and the buttons below the screen (are they virtual?) - call key, home, back
and end call.

How can this be done?

I googled that calling RegisterHotKey from coredll.dll might help but it
doesnt work.
RegisterHotKey returns 1...
Those keys still have their main function attached and the MessageWindow
(it's handle is passed as RegisterHotKey argument) isn't receiving any
messages when i click the buttons.

--
..Twigg


From: Peter Foot [MVP] on
RegisterHotKey can be used to capture (but not override) the Call, Home etc
buttons. Without seeing your code I can't comment on why this isn't working
for you.

Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

"Twigg" <no_spam_k(a)thx.k> wrote in message
news:e6u2q3qVJHA.5496(a)TK2MSFTNGP04.phx.gbl...
> Hello i'm trying to handle all the hardware buttons in my .net
> application.
> The device is HTC Touch HD - the buttons are volume up, volume down, maybe
> the turn off screen key
> and the buttons below the screen (are they virtual?) - call key, home,
> back and end call.
>
> How can this be done?
>
> I googled that calling RegisterHotKey from coredll.dll might help but it
> doesnt work.
> RegisterHotKey returns 1...
> Those keys still have their main function attached and the MessageWindow
> (it's handle is passed as RegisterHotKey argument) isn't receiving any
> messages when i click the buttons.
>
> --
> .Twigg
>

From: Twigg on
> RegisterHotKey can be used to capture (but not override) the Call, Home
> etc buttons. Without seeing your code I can't comment on why this isn't
> working for you.
>
> Peter

So you mean that i can't disable their main function using RegisterHotKey?
If so then is there any other way to do that? I want to use those keys as
normal keys in my app - my device has only those buttons, no
up,left,right,down... etc.

I'll post my code for RegisterHotKey later.

Thanks for answer.

--
..Twigg


From: Twigg on
I know what i did wrong now - i haven't unregister the hotkeys before i
registered them i my app.

Now it starts to work (when i wrote my first post i didn't know that i have
to unregister them from their main function...). I've managed to get events
from volume up, volume down, call and end call keys. My code doesn't work
for Back and Home keys. Do i need a different approach for them?
Seccond, and more important question: How do i rebind keys to their main
function after i exit my application? How to find the right window handle?

My sample code:

public partial class Form1 : Form
{

public MsgWindow msgW;

[DllImport("coredll.dll")]
protected static extern uint RegisterHotKey(IntPtr hWnd, int id,
uint fsModifiers, uint vk);

[DllImport("coredll.dll")]
protected static extern bool UnregisterFunc1(uint fsModifiers, int
id);

[DllImport("coredll.dll")]
protected static extern short GetAsyncKeyState(int vKey);


public class MsgWindow : MessageWindow
{
public MsgWindow()
{
//this.msgform = msgform;
}

// Override the default WndProc behavior to examine messages.
protected override void WndProc(ref Message msg)
{
MessageBox.Show(msg.ToString() + " msg type: " +
msg.Msg.ToString());
//msg

// Call the base WndProc method
base.WndProc(ref msg);
}
}

public Form1()
{
InitializeComponent();
int i;
UnregisterFunc1(0, 0x72); // TALK BUTTON
UnregisterFunc1(0, 0x73); // END CALL
UnregisterFunc1(0, 0x75); // VOLUME UP
UnregisterFunc1(0, 0x76); // VOLUME DOWN

UnregisterFunc1(0, 0x08); // BACK? DOESN'T WORK
UnregisterFunc1(0, 0x5B); // HOME? DOESN'T WORK

msgW = new MsgWindow();
uint result;

result = RegisterHotKey(msgW.Hwnd, 1, 0, 0x72);
result = RegisterHotKey(msgW.Hwnd, 2, 0, 0x73);
result = RegisterHotKey(msgW.Hwnd, 3, 0, 0x75);
result = RegisterHotKey(msgW.Hwnd, 4, 0, 0x76);

result = RegisterHotKey(msgW.Hwnd, 5, 0, 0x08); // doesn't work
/ BACK key
result = RegisterHotKey(msgW.Hwnd, 6, 0, 0x5B); // doesn't work
/ HOME key
}
}


From: Twigg on
Now it starts to work (when i wrote my first post i didn't know that i have
to unregister them from their main function...). I've managed to get events
from volume up, volume down, call and end call keys.Although my code doesn't
work
for Back and Home keys. Do i need a different approach for them?
Seccond, and more important question: How do i rebind keys to their main
function so they work as usual after i exit my application? How do i find
the right window handle?

My sample code:

public partial class Form1 : Form
{

public MsgWindow msgW;

[DllImport("coredll.dll")]
protected static extern uint RegisterHotKey(IntPtr hWnd, int id,
uint fsModifiers, uint vk);

[DllImport("coredll.dll")]
protected static extern bool UnregisterFunc1(uint fsModifiers, int
id);

[DllImport("coredll.dll")]
protected static extern short GetAsyncKeyState(int vKey);


public class MsgWindow : MessageWindow
{
public MsgWindow()
{
//this.msgform = msgform;
}

// Override the default WndProc behavior to examine messages.
protected override void WndProc(ref Message msg)
{
MessageBox.Show(msg.ToString() + " msg type: " +
msg.Msg.ToString());
//msg

// Call the base WndProc method
base.WndProc(ref msg);
}
}

public Form1()
{
InitializeComponent();
int i;
UnregisterFunc1(0, 0x72); // TALK BUTTON
UnregisterFunc1(0, 0x73); // END CALL
UnregisterFunc1(0, 0x75); // VOLUME UP
UnregisterFunc1(0, 0x76); // VOLUME DOWN

UnregisterFunc1(0, 0x08); // BACK? DOESN'T WORK
UnregisterFunc1(0, 0x5B); // HOME? DOESN'T WORK

msgW = new MsgWindow();
uint result;

result = RegisterHotKey(msgW.Hwnd, 1, 0, 0x72);
result = RegisterHotKey(msgW.Hwnd, 2, 0, 0x73);
result = RegisterHotKey(msgW.Hwnd, 3, 0, 0x75);
result = RegisterHotKey(msgW.Hwnd, 4, 0, 0x76);

result = RegisterHotKey(msgW.Hwnd, 5, 0, 0x08); // doesn't work
/ BACK key
result = RegisterHotKey(msgW.Hwnd, 6, 0, 0x5B); // doesn't work
/ HOME key
}
}


--
..Twigg