Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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# Unity3D始终捕获输入,即使嵌入WPF时未聚焦_C#_Wpf_Unity3d_Input - Fatal编程技术网

C# Unity3D始终捕获输入,即使嵌入WPF时未聚焦

C# Unity3D始终捕获输入,即使嵌入WPF时未聚焦,c#,wpf,unity3d,input,C#,Wpf,Unity3d,Input,我目前有一个Unity3D程序正在使用WindowsFormsHost嵌入到WPF页面中。但是,当不关注unity应用程序时,每当在页面上滚动时,exe仍会捕获该输入,并执行unity exe被支持的操作。有没有办法区分什么是团结,什么不是团结 我试着查看过程类,看看是否有任何与焦点相关的方法或属性,但没有结果。我还尝试在接受输入之前查看Unity的本机类,以检查应用程序的焦点,但同样没有效果 这就是我在WPF中嵌入应用程序的方式 [DllImport(“User32.dll”)] 静态外部布尔

我目前有一个Unity3D程序正在使用WindowsFormsHost嵌入到WPF页面中。但是,当不关注unity应用程序时,每当在页面上滚动时,exe仍会捕获该输入,并执行unity exe被支持的操作。有没有办法区分什么是团结,什么不是团结

我试着查看
过程
类,看看是否有任何与焦点相关的方法或属性,但没有结果。我还尝试在接受输入之前查看Unity的本机类,以检查应用程序的焦点,但同样没有效果

这就是我在WPF中嵌入应用程序的方式

[DllImport(“User32.dll”)]
静态外部布尔移动窗口(IntPtr句柄、intx、inty、intwidth、intheight、布尔重绘);
内部委托int WindowEnumProc(IntPtr hwnd、IntPtr LPRAM);
[DllImport(“user32.dll”)]
内部静态外部bool EnumChildWindows(IntPtr hwnd、WindowEnumProc func、IntPtr lParam);
[DllImport(“user32.dll”)]
静态外部int SendMessage(IntPtr hWnd、int msg、IntPtr wParam、IntPtr lParam);
私有过程;
私有IntPtr unityHWND=IntPtr.Zero;
私有常量int WM_ACTIVATE=0x0006;
私有只读IntPtr WA_ACTIVE=新IntPtr(1);
私有只读IntPtr WA_INACTIVE=新IntPtr(0);
private bool hasStartedOnce=false;
公共单位用户控制()
{
初始化组件();
尝试
{
StartProgram(this.Panel1.Handle.ToInt32());
}
捕获(例外e)
{
控制台写入线(e);
}
}
公用事业单位()
{
process.Kill();
这个。刷新();
}
公共Int32 GetPanelHandle()
{
返回这个.Panel1.Handle.ToInt32();
}
公共无效启动程序(Int32 panelHandleInt)
{
尝试
{
如果(文件.Exists(“SamMaintenanceRackRobot.exe”))
{
流程=新流程();
process.StartInfo.FileName=“SamMaintenanceRackRobot.exe”;
process.StartInfo.Arguments=
“-parentHWND”+panelHandleInt+”+Environment.CommandLine;
process.StartInfo.UseShellExecute=true;
process.StartInfo.CreateNoWindow=true;
process.Start();
process.waitForInputId();
睡眠(1000);
EnumChildWindows(Panel1.Handle、WindowEnum、IntPtr.Zero);
this.Load+=UserControl1\u-Load;
hasStartedOnce=正确;
}
}
已加载void UserControl1_(对象发送方,事件参数e)
{
Window Window=Application.Current.MainWindow;
窗口关闭+=窗口关闭;
}
无效窗口关闭(对象发送方,全局::System.ComponentModel.CancelEventArgs e)
{
去激活eunityWindow();
}
私有void ActivateUnityWindow()
{
发送消息(unityHWND、WM_激活、WA_激活、IntPtr.Zero);
}
私有无效停用eunitywindow()
{
发送消息(unityHWND、WM_激活、WA_非激活、IntPtr.Zero);
}
专用int WindowEnum(IntPtr hwnd、IntPtr LPRAM)
{
unityHWND=hwnd;
ActivateUnityWindow();
返回0;
}
私有空心面板1_调整大小(对象发送器、事件参数e)
{
移动窗口(unityHWND,0,0,Panel1.宽度,Panel1.高度,真);
ActivateUnityWindow();
}