how catch click event of hardware button? RRS feed

  • Question

  • hi,
    i am used VS 2005, sdk 6.0 and c# for develop WM application. i am struggling to access event of hard keys. i am able
    to get event of virtual keyboard   but i can't able to handle or fire some action of hard button on window mobile.

    please help me how i get click event of hard button?

    Friday, November 27, 2009 7:54 AM


All replies

  • Double click on the hardware button inside the Forms designer. You will get an event handler in which you can determine the hardware button you are interested in.
    Friday, November 27, 2009 9:19 AM
  • thanx mr. Maarten Struys for quick reply

     this is not correct answer what actually a want i am used HTC touch diamond 2 and i want catch event of hard key button mark with "<--" this button can not get by double clicking on hardware button inside the Forms designer.
    it give only right,left,top,bottom and center button.

     please give idea catch event of "<--" button. i am used harware button control button but form key up or down is not fired when i press "<--" button of device.
    thanx waiting for ur response....................
    Friday, November 27, 2009 12:06 PM
  • Hi Amit,

    Firstly I don't have diamond device, I don't know what the "<--" key is. I guess it is "back" key. If so, we can  use RegisterHotkey method to register "Back/Escape" key, then we can  get WM_HotKey message if we tap back key. Here is a sample in this thread:


    Best regards,
    Guang-Ming Bian - MSFT
    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Tuesday, December 1, 2009 5:35 AM
  • thanks mr. Guang-Ming Bian - MSFT,

         Your code is working when i press  back button but when i press button my application send to background.and i used meassage box to track the above information. the message box is displayed with the related information, but i cannot able to dismiss the message box by pressing the "OK" button of the message box. so i remove battery from device and dismiss message box.

    why my application send to background can i remove this behavior. and i am used multiple form when i press button from one form the event is fired in all form.
    Tuesday, December 1, 2009 7:35 AM
  • Hi A Amit,

    For preventing the application from background, we can return once we capture WM_HotKey message, like the code below:

    protected virtual int WndProc(IntPtr hwnd, uint msg, uint wParam, int lParam)



                if (msg == WM_HOTKEY)


                    return 0;





                    return CallWindowProc(mOldWndProc, this.Handle, msg, wParam, lParam);



    Best regards,
    Guang-Ming Bian - MSFT
    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Wednesday, December 2, 2009 9:48 AM