【问题标题】:Hold a key down in AutoIt在 AutoIt 中按住一个键
【发布时间】:2021-12-04 17:49:12
【问题描述】:

我正在运行这个 [非常简单的] 脚本:

#include<MsgBoxConstants.au3>

Send("{w down}")
Sleep(5000)
Send("{w up}")

我想要做的是按住“w”键5秒钟;这个脚本根本不起作用。

【问题讨论】:

  • 您真的要按住键 5 秒(只发送一次)还是要经常发送 w 5 秒?
  • 您对解决方案满意吗?

标签: autoit


【解决方案1】:

不同的解释

Opt('SendKeyDelay', 50); Default speed
_Send('w', 5000)

Func _Send($text, $milliseconds)
    $time = TimerInit()
    Do
        Send($text)
    Until TimerDiff($time) > $milliseconds
EndFunc

另一种方式不同的结果

#include <Misc.au3>

$timer=TimerInit()
Send("{w down}") ;Holds the w key down

While _IsPressed("57")
    Beep(1000, 100)       ; audiable proof
    If TimerDiff($timer) > 5000 Then ExitLoop
WEnd
Send("{w up}")    ;Releases the w key

还有一个

#include <Date.au3>
HotKeySet("1", "_hold_w") ; 1

While 1
    Sleep(250)
WEnd

Func _hold_w()
    ConsoleWrite(_NowTime(5) & @CRLF)
    Opt('SendKeyDownDelay', 5000)
    Send('w')
    ConsoleWrite(_NowTime(5) & @CRLF)
EndFunc   ;==>_hold_w

【讨论】:

    猜你喜欢
    • 2012-09-23
    • 2013-04-10
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多