Autohotkey 中的全局键盘功能?
Global keyboard function in Autohotkey?
这个脚本 "auto-presses" 按住 E。
$e::
While GetKeyState("e","P")
{
Random, r, 50, 250
sleep r
Send e
}
return
有没有办法为任意键全局调用这个函数?
例如:按住A会自动按A,Z会自动按Z等
无需手动分配代码上的每个可能的键。
我不知道有什么方法可以捕获所有密钥。但是您可以通过这种方式组合热键来简化代码:
$a::
$b::
$c::
; and so on...
$z::
RandomSendCurrentKey() ; all the above hotkeys will call RandomSendCurrentKey()
return ; 'return' is needed to prevent further execution
RandomSendCurrentKey() {
local key
StringReplace, key, A_ThisHotkey, $,, All ; removes '$' from key
While GetKeyState(key, "P")
{
Random, r, 50, 250
sleep r
Send %key%
}
}
但是为什么需要 while
循环?它也应该在没有 while
的情况下工作,因为只要您按下该键,AutoHotKey 就会继续调用该函数:
$a::
$b::
$c::
$z::
RandomSendCurrentKey()
return
RandomSendCurrentKey() {
local key
StringReplace, key, A_ThisHotkey, $,, All ; removes '$' from key
Random, r, 50, 250
sleep r
Send %key%
}
这个脚本 "auto-presses" 按住 E。
$e::
While GetKeyState("e","P")
{
Random, r, 50, 250
sleep r
Send e
}
return
有没有办法为任意键全局调用这个函数?
例如:按住A会自动按A,Z会自动按Z等
无需手动分配代码上的每个可能的键。
我不知道有什么方法可以捕获所有密钥。但是您可以通过这种方式组合热键来简化代码:
$a::
$b::
$c::
; and so on...
$z::
RandomSendCurrentKey() ; all the above hotkeys will call RandomSendCurrentKey()
return ; 'return' is needed to prevent further execution
RandomSendCurrentKey() {
local key
StringReplace, key, A_ThisHotkey, $,, All ; removes '$' from key
While GetKeyState(key, "P")
{
Random, r, 50, 250
sleep r
Send %key%
}
}
但是为什么需要 while
循环?它也应该在没有 while
的情况下工作,因为只要您按下该键,AutoHotKey 就会继续调用该函数:
$a::
$b::
$c::
$z::
RandomSendCurrentKey()
return
RandomSendCurrentKey() {
local key
StringReplace, key, A_ThisHotkey, $,, All ; removes '$' from key
Random, r, 50, 250
sleep r
Send %key%
}