2017-09-15 47 views
1

在提出这个问题之前,我对这个问题做了快速研究,我真的认为它应该起作用。有人可以指出该代码有什么问题吗?我想发送特定的文本到非活动的记事本窗口,但我没有得到任何答复。控件发送到非活动窗口 - 不起作用

SetTitleMatchMode, 2 
IfWinNotexist, Untitled - Notepad 
Run, Notepad.exe, , min 
WinWait, Untitled - Notepad 
ControlSend, Edit1, test1, Untitled - Notepad 
sleep, 1000 
ControlSend, Edit1, test2, Untitled - Notepad 
Sleep, 1000 
return 

谢谢!

+0

的代码是罚款和工作对我来说,不知道为什么它不为你工作。 – Oleg

+1

你使用哪个操作系统版本?我仍然使用Win7,但是我读到,当AHK没有使用管理员权限运行时,Win10经常会出现问题。 –

回答

0

您提供的代码已经在Windows 7上测试成功。

F3:: 
SetTitleMatchMode, 2 
IfWinNotexist, Untitled - Notepad 
Run, Notepad.exe, , min 
WinWait, Untitled - Notepad 
ControlSend, Edit1, test1, Untitled - Notepad 
sleep, 1000 
ControlSend, Edit1, test2, Untitled - Notepad 
Sleep, 1000 
return 

输出在记事本中:

test1test2 

由于@RobertIlbrink提到,有拿出取决于问题的OS上的一些行为问题。请确认AutoHotkey运行的是最新版本,并跟进更多详细信息,以便我们可以进一步排除故障。按照意见

编辑:

我想知道现在如果波兰字母表导致脚本失败的原因不匹配WinTitle。

也许尝试以下操作:

F3:: 
SetTitleMatchMode, RegEx 
Match = .*Notatnik 
IfWinNotexist, %Match% 
Run, Notepad.exe, , min 
WinWait, %Match% 
ControlSend, Edit1, test1, %Match% 
sleep, 1000 
ControlSend, Edit1, test2, %Match% 
Sleep, 1000 
return 
+0

我正在Windows 7上运行此脚本,并使用最新版本的AHK和管理员权限 - 我已经检查了两次。有趣的是,其他命令似乎工作正常。我在其他项目中使用“发送”命令,我没有问题。 –

+0

@MateuszKnap也许可以考虑使用Window Spy来查看记事本在系统中实际显示的内容。 –

+0

我有Windows的波兰语版本,所以WinTitle是“Beztytułu - Notatnik”。这是唯一的区别。尽管如此,即使我正在改变有关这一事实的代码 - 仍然没有任何反应。 –