问题模拟多个KeyPress

时间:2014-05-29 14:35:48

标签: c# kinect simulation kinect-sdk

我想在我的手势应用程序上模拟多个按键式(Shift + UP)或鼠标滚动。

这是我的KeyPressEmulator班级

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 );
        }

    }
}

这就是女性称之为谷歌地球过程的主要窗口

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

例如:0x22模拟&#39; previeus页面&#39;和Google地球上的区域。

所以,如果我想要模拟&#39; Shift + UP&#39;或者&#39;鼠标滚动&#39;我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

尝试MultiThreading。创建一个多线程,以便您可以一次发送多个密钥。

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

CreateThread(0,0x1000,&Send_Key2,NULL,0,NULL);
//untested