长按 = 大写

Long-press = Capitalize

预期的热键功能:如果按键时间超过 0.2 秒,则字符大写

出现问题:快速连续键入“vbnm”时(这意味着我正在按下一个键同时仍然按住前一个键)然后 AHK 输出 x 倍首先按下的键,结果是“vvvv”。

这就是代码。请帮帮我 (y) :-)

$y::
$x::
$c::
$v::
$b::
$n::
$m::
    key := SubStr(A_ThisHotkey, 2)  
    ;MsgBox, %key% ;it recognizes/shows all keys pressed correctly,
    ;but in the end it prints just x-times the key that was pressed first
    ;whereby x is the number of keys pressed very quickly in a row

    KeyWait, %key%, T0.2 ;Long press = capitalize
    If ErrorLevel
        SendInput +%key%    
    Else
        SendInput %key%         
Return

尝试:

$y:: 
$x::  
$c::
$v::
$b::
$n::
$m::keyFunc(SubStr(A_ThisHotkey, 2))

keyFunc(key) {   
    KeyWait, %key%, T0.3 ;Long press = capitalize
    SendInput % ErrorLevel ? Format("{:U}", key) : key  
Return
}

所以最后这段代码似乎可以工作,除了按住键太久会带来一些不便,导致例如"Oo".

;For normal characters ......
$x::
$c::
$v::
$b::
$n::
$m::keyFunc(SubStr(A_ThisHotkey, 2))
keyFunc(key) {   
    Critical
    KeyWait, %key%, T0.3 ;Long press = capitalize
    SendInput % ErrorLevel ? Format("{:U}", key) : key  
Return 
}

;For special characters ......
::
::
::
::
::
::
::
::
$sc01A:: ;ü
$sc027:: ;ö
$sc028:: ;ä
$sc00C:: ;ß
$sc033:: ;,
$sc034:: ;. 
$sc035:: ;-
$sc01B:: ;+
$sc02B:: ;#
$sc00D::  keyFunc2(SubStr(A_ThisHotkey, 2))
keyFunc2(key) {
    Critical  
    KeyWait, %key%, T0.3 ;Long press = capitalize   
    If ErrorLevel
        SendInput +{%key%}
    Else
        SendInput {%key%}
Return
}