From: Trevor on
"Twigg" <no_spam_k(a)thx.k> wrote in message
news:OY6xq0PWJHA.1788(a)TK2MSFTNGP06.phx.gbl...
> 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
>

You can also PInvoke GAPI to intercept hardware key presses. See
GXOpenInput for more information.

From: Donald on

Hey Twigg,

Any luck with your problem? I too am trying to catch these two buttons on
Windows Mobile 6.1 using CF 2.0 and have not figured out how.

Thanks,
Donald

"Twigg" wrote:

> 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
>
>
>