区分物理击键和重复键
Discern between physical key stroke and repeated key
在 Autohotkey 中:有没有办法区分物理击键和重复键?
我正在 dot net 中寻找 KeyEventArgs.IsRepeat 的等价物。
我希望能找到像这样更好的东西:
*key1::
If (hotkey1_active)
return
hotkey1_active := 1
Myfunction1()
return
*key1 up::
hotkey1_active := 0
return
找到以上示例代码here
据我所知,没有用于按键检查的内置语法。但是您可以在循环中使用 getkeystate 检查状态:
key := "a"
state0 := getkeystate(key, "P") ; init key state
c := 0
loop
{
sleep 30 ; sleep to reduce CPU usage
state1 := getkeystate(key, "P") ; getkeystate
state_on := (state1 > state0) ; check if key state is changed to 'on'
; state_off := (state1 < state0) ; check if key state is changed to 'off'
state0 := state1 ; save previous state
if (state_on) {
c += 1
tooltip %key% pressed %c% times
; Myfunction1()
}
}
这很有可能是物理状态的变化。
没有办法知道,唯一知道的是重复包括按键按下而没有按键抬起。
也许有一些方法可以不必为每个热键创建一个变量。
试试这个,我认为它在正常情况下就足够了:
*a::
if (A_PriorHotkey = A_ThisHotKey)
return
Myfunction1()
return
*a Up:: return ; Does nothing but change A_PriorHotkey.
在 Autohotkey 中:有没有办法区分物理击键和重复键?
我正在 dot net 中寻找 KeyEventArgs.IsRepeat 的等价物。
我希望能找到像这样更好的东西:
*key1::
If (hotkey1_active)
return
hotkey1_active := 1
Myfunction1()
return
*key1 up::
hotkey1_active := 0
return
找到以上示例代码here
据我所知,没有用于按键检查的内置语法。但是您可以在循环中使用 getkeystate 检查状态:
key := "a"
state0 := getkeystate(key, "P") ; init key state
c := 0
loop
{
sleep 30 ; sleep to reduce CPU usage
state1 := getkeystate(key, "P") ; getkeystate
state_on := (state1 > state0) ; check if key state is changed to 'on'
; state_off := (state1 < state0) ; check if key state is changed to 'off'
state0 := state1 ; save previous state
if (state_on) {
c += 1
tooltip %key% pressed %c% times
; Myfunction1()
}
}
这很有可能是物理状态的变化。
没有办法知道,唯一知道的是重复包括按键按下而没有按键抬起。
也许有一些方法可以不必为每个热键创建一个变量。
试试这个,我认为它在正常情况下就足够了:
*a::
if (A_PriorHotkey = A_ThisHotKey)
return
Myfunction1()
return
*a Up:: return ; Does nothing but change A_PriorHotkey.