1

I want to simulate multiple keypress -like (Shift+UP) or the scroll of the mouse- on my gesture-application.

This is my KeyPressEmulator class

static class KeyPressEmulator
{
    const UInt32 WM_KEYDOWN = 0x0100;
    const UInt32 WM_KEYUP = 0x0101;

    [DllImport("user32.dll")]
    static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);

    [STAThread]
    public static void setKeyPressed(int key, Boolean pressed)
    {
        Process[] processes = Process.GetProcessesByName("googleearth");

        foreach (Process proc in processes)
        {
            PostMessage(proc.MainWindowHandle, pressed ? WM_KEYDOWN : WM_KEYUP, key,0 );
        }

    }
}

And this is the main window witch call the google earth processes

private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
    Skeleton first = GetFirstSkeleton(e);
    Dictionary<BaseGesture, int> gestures = new Dictionary<BaseGesture, int>();
    gestures.Add(new HandsOut(), 0x22);
    gestures.Add(new HandsIn(), 0x21);
    gestures.Add(new PanUp(), 0x58);
    gestures.Add(new PanDown(), 0x43);
    gestures.Add(new PanLeft(), 0x42);
    gestures.Add(new PanRight(), 0x56);

    foreach (BaseGesture gesture in gestures.Keys)
        KeyPressEmulator.setKeyPressed(gestures[gesture], false);

    foreach (BaseGesture gesture in gestures.Keys)
    {
        if (gesture.CheckGesture(first) == GestureResult.Success)
        {
            KeyPressEmulator.setKeyPressed(gestures[gesture], true);
            break;
        }
    }
}

For example: 0x22 simulate the 'previeus page' and zone on google earth.

so if i want the simulate 'Shift+UP' or 'the scroll of the mouse' how can i do this?

lavrton
  • 18,973
  • 4
  • 30
  • 63
  • I am trying to do similar thing, can you answer this? http://stackoverflow.com/questions/26023232/control-google-earth-using-kinect-gestures – Faizan Sep 25 '14 at 07:49

1 Answers1

0

Try MultiThreading. Creating a multiple thread so you can send multiple keys at once.

    DWORD WINAPI Send_Key2(LPVOID lParam)
{
//code
//code
return NULL;
}

CreateThread(0,0x1000,&Send_Key2,NULL,0,NULL);
//untested
Roblox Man225
  • 75
  • 1
  • 8