首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AutoHotkey (AHK):GetKeyState不承认ControlSend制造的按键

AutoHotkey (AHK):GetKeyState不承认ControlSend制造的按键
EN

Stack Overflow用户
提问于 2014-12-21 02:57:56
回答 2查看 854关注 0票数 1

我有一个非常复杂的脚本,可以按下一个键,并且需要检查键是否仍然按下,所以GetKeyState看起来很完美,但是我无法让它工作,所以我只做了一个简单的脚本,它仍然不承认状态。

该脚本如下:

代码语言:javascript
运行
复制
    #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键进行适当的交互。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-21 07:52:16

我同意blackholyman的观点:“当GetKeyState获得密钥的全局系统状态时,GetKeyState将不适用于控制发送,而controlsend只在本地设置状态,也就是说,键状态只为一个控件或窗口设置。”

但是,如果您需要“用于某些窗口函数的ControlSend,例如通过PID发送命令”,我认为您也可以使用发送命令来完成它。使用WinActivate激活您需要发送密钥的窗口,然后使用发送来发送密钥。您可以在WinActivate命令中使用PID,而不是使用温蒂参数,更详细地介绍一下:http://ahkscript.org/docs/misc/WinTitle.htm

试试下面的代码:

代码语言:javascript
运行
复制
#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.
}
票数 2
EN

Stack Overflow用户

发布于 2014-12-21 07:35:20

当GetKeyState获得密钥的全局系统状态时,GetKeyState将不能用于控制发送,但controlsend只在本地设置状态,即只为一个控件或窗口设置密钥状态。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27586335

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档