Send keys on smartphone

Hi all,

I'd want to know to send a key in my application. I just want that my application go back at the begenning of the phone, as if i presse the "Home" key (the key with a little house on).

So i think i have to use keybd_event or PostKeybdMessage but i don't know what are the arguments that i can use.

I know the virtual key word for home: is 0x24.

I just want when i use cameracapturedialog to close correctly the application and not have the capturedialog after exiting my application...

[DllImport("coredll.dll", SetLastError=true)]

internal static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

[DllImport("coredll.dll")]

private static extern bool PostKeybdMessage(IntPtr hwnd, uint vKey, uint KeyStateFlags, uint cCharacters, uint[] pShiftStateBuffer, uint[] pCharacterBuffer);



Answer this question

Send keys on smartphone

  • John Oliver (UK)MSP, VSIP

    Get a handle to the window of your application and send a message e.g. below

    int hwnd = GetForegroundWindow();

    SendMessage(hwnd, 0x0111, 1, 0); //param values are random - please use the correct ones for your app

    Manav



  • GTrz

    Thanks mgaur_MSFT. But I find how to simulate home key press, so it comes back at the begining, and I can close the application after.

    here's the code :

    public void CloseCameraApp()

    {

    byte VK_HOME= 0x5b; // on Smartphone

    const int KEYEVENTF_KEYUP = 0x2;

    const int KEYEVENTF_KEYDOWN = 0x0;

    keybd_event(VK_HOME, 0, KEYEVENTF_KEYDOWN, 0);

    keybd_event(VK_HOME, 0, KEYEVENTF_KEYUP, 0);

    }

    [DllImport("coredll.dll", SetLastError = true)]

    static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);


  • Send keys on smartphone