我使用Tobii Eyetracker进行c#项目。目标是将某个键输入(即F5刷新)发送到当前注视的窗口。
const UInt32 WM_KEYDOWN = 0x0100;
const int VK_F5 = 0x74;
Hook.GlobalEvents().OnCombination(new Dictionary<Combination, Action> {
{Combination.FromString("Shift+Alt+L"), () => {
// get IntPtr of gazed at window and sets it active, this works
IntPtr newWindow = WindowFromPoint(new Point(xCord,yCord));
SetForegroundWindow(newWindow);
SetActiveWindow(newWindow);
// should send "F5" to the window thats gazed at
PostMessage(newWindow, WM_KEYDOWN, VK_F5, 0);
}
}
});
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
使用NuGet包globalMouseKeyHook捕获输入并且可以正常工作。 但是,如果另一个窗口处于活动状态且之前接收到输入,则PostMessage仅发送F5命令。因此它不会刷新当前窗口(即使它保持活动状态),如果前一个窗口没有接收到任何输入,也不会刷新另一个窗口(即使新窗口设置正确)积极的。)