【问题标题】:How do I send output to an inactive window for better AFK? (AutoHotkey)如何将输出发送到非活动窗口以获得更好的 AFK? (自动热键)
【发布时间】:2020-08-26 21:37:23
【问题描述】:
我正在尝试使用计算机上的自动热键将我的代码输出发送到非活动应用程序,这样我就不必在屏幕上做其他事情了。我将如何实施它?
F1::
stop := 0
Loop
{
Send, z
Sleep 500
}until Stop
return
F2::Stop := 1
这是我到目前为止的代码,有什么帮助吗?
【问题讨论】:
标签:
automation
keyboard
autohotkey
keypress
【解决方案1】:
ControlSending 可能会起作用。这基本上是一个成功或失败。它适用于某些应用程序,而对于某些应用程序则不行。
不过,您值得一试。
此外,您将要使用timer,而不是在热键线程中循环。 Timer 仅用于这样的事情,由于各种原因,您所做的是一种不好的做法。
;timer runs the user-defined function "SendZ" every 500ms
F1::SetTimer, SendZ, 500
F2::SetTimer, SendZ, Off
SendZ()
{
ControlSend, , z, % "ahk_exe notepad.exe"
}
作为奖励,我们甚至可以编写一个可爱的单行代码来通过使用三元来打开/关闭该计时器:
F1::SetTimer, SendZ, % (Toggle:=!Toggle) ? 500 : "Off"
如果这对你没有意义,并且你有兴趣,你可以阅读我之前关于它的冗长解释here。