我用kinect做了一些软件来分类手势,想用这些手势在电脑上运行的模拟器上玩马里奥游戏。
为了播放它,我尝试将击键发送到模拟器。在我的代码中,我首先打开了窗口(这有效):
Process process = Process.GetProcessesByName("nnnesterJ")[0];
SetForegroundWindow(process.MainWindowHandle);
然后我尝试发送击键:
case Movement.left: SendKeys.SendWait("{LEFT}"); break;
case Movement.right: SendKeys.SendWait("{RIGHT}"); break;
case Movement.upperleft: SendKeys.SendWait("{LEFT}{UP}"); current_move = Movement.stop; break;
case Movement.upperright: SendKeys.SendWait("{RIGHT}{UP}"); current_move = Movement.stop; break;
case Movement.jump: SendKeys.SendWait("{UP}"); current_move = Movement.stop; break;
case Movement.crouch: SendKeys.SendWait("{DOWN}"); break;
但是,这不起作用:(我确实在excel中尝试过,然后它确实起作用了(是的,我确定键实际上是正确的)。
我也试过这样做:
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
public static void PressKey(Keys key, bool up)
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
if (up)
{
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
}
else
{
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
}
}
但不幸的是,这也行不通。有人有一些选择吗?
亲切的问候,赫克托