Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用c语言向不同窗口发送键#_C#_Windows_Postmessage - Fatal编程技术网

C# 用c语言向不同窗口发送键#

C# 用c语言向不同窗口发送键#,c#,windows,postmessage,C#,Windows,Postmessage,我在c#的一个项目中使用Tobii Eyetracker。目标是将某个键输入(即F5刷新)发送到当前注视的窗口 const UInt32 WM_KEYDOWN = 0x0100; const int VK_F5 = 0x74; Hook.GlobalEvents().OnCombination(new Dictionary<Combination, Action> { {Combination.FromString("Shift+Alt+L"), () => {

我在c#的一个项目中使用Tobii Eyetracker。目标是将某个键输入(即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);
const UInt32 WM_KEYDOWN=0x0100;
常数int VK_F5=0x74;
Hook.GlobalEvents().onComposition(新字典{
{composition.FromString(“Shift+Alt+L”),()=>{
//获取凝视窗口的IntPtr并将其设置为活动状态,此操作有效
IntPtr newWindow=WindowFromPoint(新点(xCord,yCord));
SetForegroundWindow(新窗口);
SetActiveWindow(新窗口);
//应该发送“F5”到被注视的窗口
PostMessage(newWindow,WM_KEYDOWN,VK_F5,0);
}
}
});
[DllImport(“user32.dll”)]
静态外部bool PostMessage(IntPtr hWnd、UInt32 Msg、intwparam、intlparam);
输入由NuGet包捕获并工作。
但是,只有当另一个窗口处于活动状态且之前收到输入时,PostMessage才会发送F5命令。因此,它不会刷新当前窗口(即使它保持活动状态),如果前一个窗口没有收到任何输入(即使新窗口被正确设置为活动状态),它也不会刷新另一个窗口。

操作系统本身不会发送
WM\u KEYDOWN
,因此,当应用程序单独接收到该消息时,可能无法正常运行(例如,应用程序可能会对“按键”或“向上键”消息进行处理)。当按下物理键盘键时,尝试使用Spy++观察键盘消息的完整序列,然后发布整个序列。可能重复