I'm using the Tobii Eyetracker for a project in c#. The goal is to send a certain key input (i.e. F5 to refresh) to the window that's currently gazed at.
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);
The input is captured with the NuGet package globalMouseKeyHook and works. But the PostMessage only sends the F5 command if another window is active and previously received inputs. So it doesn't refresh the current window (even though it stays active), and also doesn't refresh another window if the previous one didn't receive any inputs (even though the new window is correctly set as active).