我有一个非常复杂的脚本,可以按下一个键,并且需要检查键是否仍然按下,所以GetKeyState看起来很完美,但是我无法让它工作,所以我只做了一个简单的脚本,它仍然不承认状态。
该脚本如下:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
~#Right::
ControlSend,, {d down}, ahk_pid 6920
Loop{
GetKeyState, dState, d
;MsgBox, d Key State: %dState%
SplashTextOn,300,50, AutoNavigatorInfo, d Key State: %dState%
WinMove, AutoNavigatorInfo, , 300, 0 ; Move the splash window to the top left corner.
}
遗憾的是,我使用的splashText窗口一直将dState中继为U
。奇怪的是,在我使用的测试窗口中,它正在与按下的d键进行适当的交互。
发布于 2014-12-21 07:52:16
我同意blackholyman的观点:“当GetKeyState获得密钥的全局系统状态时,GetKeyState将不适用于控制发送,而controlsend只在本地设置状态,也就是说,键状态只为一个控件或窗口设置。”
但是,如果您需要“用于某些窗口函数的ControlSend,例如通过PID发送命令”,我认为您也可以使用发送命令来完成它。使用WinActivate激活您需要发送密钥的窗口,然后使用发送来发送密钥。您可以在WinActivate命令中使用PID,而不是使用温蒂参数,更详细地介绍一下:http://ahkscript.org/docs/misc/WinTitle.htm
试试下面的代码:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
~#Right::
WinActivate, ahk_pid 6920
Send, {d down}
Loop{
GetKeyState, dState, d
;MsgBox, d Key State: %dState%
SplashTextOn,300,50, AutoNavigatorInfo, d Key State: %dState%
WinMove, AutoNavigatorInfo, , 300, 0 ; Move the splash window to the top left corner.
}
发布于 2014-12-21 07:35:20
当GetKeyState获得密钥的全局系统状态时,GetKeyState将不能用于控制发送,但controlsend只在本地设置状态,即只为一个控件或窗口设置密钥状态。
https://stackoverflow.com/questions/27586335
复制相似问题