AutoHotKey 脚本。如果输入之间的间隔小于 150 毫秒,则纠正重复字符

问题描述 投票:0回答:2

请帮忙。 我的键盘(雷柏 E9260)有一个缺陷:打字时字符会随机加倍。 我需要一种方法来修复这个缺陷。也许是 .ahk 脚本。

例如,如果输入了字符“a”,并且在不到150毫秒后输入了相同的字符,则多余的字符将被删除,或者“aa”将被替换为“a”。否则,如果输入之间的间隔超过 150 毫秒 – 不执行任何操作。

示例(不起作用):

#NoEnv
SendMode Input

previousKey := ""
previousTime := 0

SetTimer, DeleteDuplicate, -150

DeleteDuplicate:
    currentTime := A_TickCount
    if (currentTime - previousTime < 150)
    {
        SendInput {Backspace}
        SendInput {%previousKey%}
    }
    previousKey := ""
    previousTime := 0
return

$*::
    currentKey := A_ThisHotkey
    currentTime := A_TickCount
    if (currentKey = previousKey && currentTime - previousTime < 150)
    {
        previousKey := currentKey
        previousTime := currentTime
        return
    }
    previousKey := currentKey
    previousTime := currentTime
return
autohotkey keyboard-events
2个回答
1
投票
#NoEnv
#SingleInstance Force

#UseHook

keys = a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0 ;...
Loop,Parse,keys, `,
    Hotkey, %A_LoopField%, DeleteDuplicate
return

DeleteDuplicate:   
    If (A_PriorHotKey = A_ThisHotkey AND A_TimeSincePriorHotkey < 300)
        return ; don't send it
    SendInput, %A_ThisHotkey%
return

编辑:

如果您对不同语言使用多种键盘布局,请将“keys”中的每个键替换为其 scancode,将

SendInput, %A_ThisHotkey%
替换为
SendInput, {%A_ThisHotkey%}

例如在我的系统上,SC01E 是 a 键的扫描码,b 是 SC030,c 是 SC02E,d 是 SC020,这适用于所有键盘布局:

#NoEnv
#SingleInstance Force

#UseHook

keys = SC01E,SC030,SC02E,SC020
Loop,Parse,keys, `,
    Hotkey, %A_LoopField%, DeleteDuplicate
return

DeleteDuplicate:   
    If (A_PriorHotKey = A_ThisHotkey AND A_TimeSincePriorHotkey < 300)
        return ; don't send it
    SendInput, {%A_ThisHotkey%}
return

并确保您的脚本保存为 UTF-8 with BOM


0
投票
#NoEnv
#SingleInstance Force

#UseHook

keys = SC029,SC010,SC011,SC012,SC013,SC014,SC015,SC016,SC017,SC018,SC019,SC01A,SC01B,SC01E,SC01F,SC020,SC021,SC022,SC023,SC024,SC025,SC026,SC027,SC028,SC02B,SC02C,SC02D,SC02E,SC02F,SC030,SC031,SC032,SC033,SC034,SC035
; I used the ahk ScanCode script. I pressed all the keys in turn, they were automatically copied to the buffer, and then through Ditto I pressed Ctrl+n in turn and pasted the codes.

Loop,Parse,keys, `,
    Hotkey, %A_LoopField%, DeleteDuplicate
return

DeleteDuplicate:   
    If (A_PriorHotKey = A_ThisHotkey AND A_TimeSincePriorHotkey < 90)
        return ; don't send it
    SendInput, {%A_ThisHotkey%}
return
© www.soinside.com 2019 - 2024. All rights reserved.