首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模拟多个KeyPress的问题

模拟多个KeyPress的问题
EN

Stack Overflow用户
提问于 2014-05-29 22:35:48
回答 1查看 205关注 0票数 1

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

这是我的KeyPressEmulator

代码语言:javascript
复制
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 );
        }

    }
}

这是调用google earth进程的主窗口

代码语言:javascript
复制
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在谷歌地球上模拟'previeus page‘和zone。

那么,如果我想要模拟的“Shift+UP”或“鼠标的滚动”,我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2016-10-03 04:28:38

试试MultiThreading。创建一个多线程,这样你就可以一次发送多个密钥。

代码语言:javascript
复制
    DWORD WINAPI Send_Key2(LPVOID lParam)
{
//code
//code
return NULL;
}

CreateThread(0,0x1000,&Send_Key2,NULL,0,NULL);
//untested
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23935948

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档