【问题标题】:AutoHotkey: Key debounce for fixing keyboard chatter, but accounts for holding down keysAutoHotkey:用于修复键盘颤动的键去抖动,但用于按住键
【发布时间】:2013-03-03 06:58:18
【问题描述】:

我的键盘出现问题,我在某些键上遇到了非常糟糕的键盘颤动。我设法找到了一个自动热键脚本,它有助于过滤键盘上的按键,但是它实际上所做的是在按住它时重复发送相同的键,当我使用需要键的应用程序时,这给我带来了问题按住某些快捷方式(Maya、XSI 等)

我尝试使用 {blind} 标志修改 SendInput 命令并将 'down' 修饰符添加到 %k_ThisHotkey%,但我无法让它正常工作。

(我为第一个 sendinput 添加了一个“down”,并执行了 GetKeyState 以检查键是否被按住,然后执行了一个条件,如果键被释放,SendInput up 将执行。但是,这没有按预期工作,我没有想法。)

有人愿意就我如何让一个适当的去抖动脚本工作,同时还允许按住按键给出一些指示吗?

谢谢!

; ---- setups
#UseHook On
;Capslock::LShift


; ---- initialize parameters
if (%0% > 0)
    k_TimeThreshold = %1%
else
    k_TimeThreshold = 40
;k_TimeThreshold = 1000  ; for debugging


; ---- initialize variables
k_LastHotkey = 0
k_LastTick := A_TickCount


; ---- Set all keys as hotkeys. See www.asciitable.com
k_ASCII = 33
Loop
{
    Transform, k_char, Chr, %k_ASCII%

    Hotkey, %k_char%, k_KeyPress

        if ((k_char Not In +,^)  AND  (k_ASCII != 123  AND k_ASCII != 125))
    {
        Hotkey, +%k_char%, k_KeyPress       ; shift
        ; Hotkey, ^%k_char%, k_KeyPress     ; control
        ; Hotkey, !%k_char%, k_KeyPress     ; alt
        ; Hotkey, #%k_char%, k_KeyPress     ; win
    }

    if k_ASCII = 64
        k_ASCII = 91
    else if k_ASCII = 126
        break
    else
        k_ASCII++
}
return 

; ---- End of auto-execute section.


; ---- When a key is pressed by the user, send it forward only if it's not a "bounce"
; ---- A "bounce" is defined as: "key is same as last"  AND  "time since last key is very short"
Enter::
Space::
Tab::
Esc::
BS::
Del::
Ins::
Home::
End::
PgUp::
PgDn::
Up::
Down::
Left::
Right::
k_KeyPress:
{
    k_ThisHotkey := A_ThisHotkey        ; grab the current hotkey
    k_ThisTick := A_TickCount       ; grab the current tick
    ElapsedTime := k_ThisTick - k_LastTick  ; time since last hotkey (ticks)

    if (ElapsedTime > k_TimeThreshold  ||  k_ThisHotkey <> k_LastHotkey)
    {
        if k_ThisHotkey In !,#,^,+,{,},Enter,Space,Tab,Esc,BS,Del,Ins,Home,End,PgUp,PgDn,Up,Down,Left,Right
            SendInput {%k_ThisHotkey%}
        else
            SendInput %k_ThisHotkey%
        ;SendInput %ElapsedTime%  ; for debugging
    }

    k_LastHotkey := k_ThisHotkey    ; store the current hotkey for next time
    k_LastTick := k_ThisTick    ; store the current tick for next time
}
return

; ---- other keys that could be filtered (but caused issues on some keyboards)
;LWin::
;RWin::
;LAlt::
;RAlt::

【问题讨论】:

  • 换个新键盘怎么样?除非它是那些昂贵的游戏之一,否则键盘非常便宜。不过我喜欢挑战!
  • 但是但是它是机械键盘:X
  • 那些好的旧键盘之一(F1 - F24)......?
  • 不,一个更现代的 Filco :X 但至少我在它第一次出现时就知道了,所以我不是一个时髦的人。对吧??!

标签: keyboard autohotkey


【解决方案1】:

这是一个想法。不确定它是否能解决您的问题。让我知道。我可以使用 Shift 来移动字母,弹跳键和普通按键之间有明显的区别。我只用 Shiftqa 对其进行了测试。

#SingleInstance Force
#installKeybdHook
#Persistent

Shift::
q::
a::
keywait, %A_ThisHotkey%
if (A_PriorHotkey = A_ThisHotkey AND A_TimeSincePriorHotkey < 900)  ; bouncy key
{
    Soundbeep, 500, 200
    Return
}
Soundbeep, 2000, 200
return

【讨论】:

  • 我尝试用 SendInput {%A_ThisHotkey% down} 替换 soundbeep 部分,然后执行相同的 GetKeyState 操作以检查何时释放键,然后发送相应的向上输入,但我仍然得到相同的行为。 =\ 主要问题是如何在考虑按下热键的同时考虑喋喋不休?
  • 我试图避免你对修饰符的下调。但是当我用 Send, %A_ThisHotkey% 替换哔哔声时,它(还)没有像我预期的那样工作。
  • 哦,顺便说一句。为避免循环(发送字符会导致再次触发热键),您需要在每个热键前放置一个 $ 符号。不幸的是,$ 出现在A_ThisHotkey 变量的前面。因此,当您按下 [a] 时,A_ThisHotkey 变量会显示“$a”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-04
  • 1970-01-01
  • 2012-08-08
  • 1970-01-01
  • 2011-09-20
  • 1970-01-01
相关资源
最近更新 更多