我想在我的手势应用程序上模拟多个按键-like (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 );
}
}
}这是调用google earth进程的主窗口
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”或“鼠标的滚动”,我该怎么做呢?
发布于 2016-10-03 04:28:38
试试MultiThreading。创建一个多线程,这样你就可以一次发送多个密钥。
DWORD WINAPI Send_Key2(LPVOID lParam)
{
//code
//code
return NULL;
}
CreateThread(0,0x1000,&Send_Key2,NULL,0,NULL);
//untestedhttps://stackoverflow.com/questions/23935948
复制相似问题