[英]Changing focus with Autohotkey, what is going on?
I just want my script to select the right Window to input key storkes. 我只希望我的脚本选择正确的窗口来输入按键。 To do this I think I use WinActivate. 为此,我认为我使用WinActivate。 I ran the example from their site but found some strange results in Windows 10 我从他们的网站上运行了示例,但在Windows 10中发现了一些奇怪的结果
IfWinExist, Untitled - Notepad
WinActivate ; use the window found above
else
WinActivate, Calculator;
What is causing the inconsistency? 是什么导致不一致?
It happens because of the implementation of the WinActivate function on the language. 发生这种情况是因为在该语言上实现了WinActivate函数。 WinActivate tries to open an window, but it might not be able to. WinActivate尝试打开一个窗口,但可能无法打开。 From the documentation 从文档中
Six attempts will be made to activate the target window over the course of 60ms. 将在60ms内尝试进行六次激活目标窗口的操作。 Thus, it is usually unnecessary to follow WinActivate with WinWaitActive or IfWinNotActive. 因此,通常不需要在WinActivate后面加上WinWaitActive或IfWinNotActive。
Usually you can try the #WinActivateForce directive in combination with WinWaitActive or IfWinNotActive . 通常,您可以将#WinActivateForce指令与WinWaitActive或IfWinNotActive结合使用。
Sometimes you can use an ahk_exe parameter to match the window. 有时您可以使用ahk_exe参数来匹配窗口。 It may work in cases where the window title doesn't. 在窗口标题不起作用的情况下可能会起作用。 In this case you would use 在这种情况下,您将使用
Also it's useful to try restoring the window with WinRestore . 尝试使用WinRestore还原窗口也很有用。
SetTitleMatchMode, 2
IfWinExist, Bloco de notas
{
WinActivate ; use the window found above
}
else
{
WinRestore, ahk_exe calc.exe
WinActivate, ahk_exe calc.exe
}
I'm on Win7, but the above worked for me. 我在Win7上,但是以上方法对我有用。
Here is an example of a good and complete implementation of a function that tries to activate a window. 这是尝试激活窗口的功能的良好完整实现的示例 。
Semicolons introduce comments in AHK. 分号在AHK中引入评论。 There has to be a white space before it, otherwise it's seen as part of the string (alias winactivate "Calculator;") 前面必须有一个空格,否则它将被视为字符串的一部分(别名winactivate“ Calculator;”)
so, use 因此,使用
WinActivate, Calculator ;
or just omit the ;
或只是省略;
, for it doesn't contribute anything ,因为它没有任何贡献
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.