Answers:
实际上,可以使用AHK计时器脚本来完成此操作。该脚本将在按下Caps Lock时注册,并拦截Capslock Up,仅在经过一定毫秒数后才触发。默认超时为0.2秒,可以在系统托盘中配置。
; AutoHotKey - Suppress CapsLock
; This is a modified version of a scrpt by Lexikos, taken from:
; http://www.autohotkey.com/board/topic/82509-software-fix-for-double-clicking-mouse/
RegRead minDelay, HKCU, Software\LongCapsLock, MinDelay
if ErrorLevel
minDelay := 200 ; Default setting.
#NoTrayIcon ; Hide initial icon.
Menu Tray, Icon, %A_WinDir%\System32\main.cpl ; Set icon.
Menu Tray, Icon ; Show icon.
Menu Tray, NoStandard
Menu Tray, Add, &Configure, TrayConfigure
Menu Tray, Add, E&xit, TrayExit
Menu Tray, Default, &Configure
Menu Tray, Click, 1 ; Single-click to configure.
Menu Tray, Tip, Long CapsLock
global _starttime
global timing := 0
CapsLock::
if (timing = 0) {
timing := 1
_startTime := A_TickCount
}
return
CapsLock Up::
if (timing = 1) {
_timeDiff := A_TickCount - _startTime
;MsgBox diff: %_timeDiff%
if (_timeDiff > minDelay) {
Send {CapsLock down}
}
timing := 0
}
return
TrayConfigure:
prompt := "Enter minimum duration needed to hold Caps Lock`n"
. "before it is toggled. The unit is milliseconds."
Loop {
InputBox newMinDelay, Long CapsLock, %prompt%,,,,,,,, %minDelay%
if ErrorLevel ; Cancelled?
return
if (newMinDelay+0 >= 150 && newMinDelay <= 10000) ; Valid?
break
if (A_Index = 1)
prompt .= "`n`nPlease enter a number between 150 and 10000."
}
minDelay := newMinDelay
if (minDelay = 200)
RegDelete HKCU, Software\LongCapsLock
else
RegWrite REG_DWORD, HKCU, Software\LongCapsLock, MinDelay, %minDelay%
return
TrayExit:
ExitApp
我这里有两个AHK脚本。如果您希望我解释的内容超出了脚本中的注释,请在下面添加注释。
第一个比较复杂,可能会发生故障,但是按住一秒钟后,它将CapsLock发送为实际按键。
第二个按钮切换“ Caps Lock”的状态,如果您希望延迟的原因是某些其他程序的CapsLock热键,则可能不希望这样做。
您可以通过Delay
在第二行中更改变量来配置延迟。
; Time to wait in milliseconds
Delay = 1000
; Variable used to ignore key repeats
; (Windows sends them when a key is held down)...
CapsLockHeld = 0
; This starts the timer on key *down*.
; Time is measured in milliseconds.
; Timer resolution should be approximately 20 ms.
; The negative time means run only once.
; It will reset the timer if it is already running.
CapsLock::CapsLockDown()
; This stops the timer on key *up*.
CapsLock Up::CapsLockUp()
; This sends a CapsLock keypress when the timer runs out.
SendCapsLock:
SetTimer, SendCapsLock, Off
HotKey, CapsLock, Off
HotKey, CapsLock Up, Off
SendInput, {CapsLock}
HotKey, CapsLock Up, On
HotKey, CapsLock, On
Return
; Using functions because otherwise global variables die
CapsLockDown() {
global CapsLockHeld
global Delay
If (CapsLockHeld == 1) {
Return
}
CapsLockHeld = 1
SetTimer, SendCapsLock, %Delay%
Return
}
CapsLockUp() {
global CapsLockHeld
CapsLockHeld = 0
SetTimer, SendCapsLock, Off
Return
}
; Time to wait in milliseconds
Delay = 1000
; Variable used to ignore key repeats
; (Windows sends them when a key is held down)...
CapsLockHeld = 0
; This starts the timer on key *down*.
; Time is measured in milliseconds.
; Timer resolution should be approximately 20 ms.
; The negative time means run only once.
; It will reset the timer if it is already running.
CapsLock::CapsLockDown()
; This stops the timer on key *up*.
CapsLock Up::CapsLockUp()
; This sends a CapsLock keypress when the timer runs out.
SendCapsLock:
SetTimer, SendCapsLock, Off
If (GetKeyState("CapsLock", "T"))
SetCapsLockState, Off
Else
SetCapsLockState, On
Return
; Using functions because otherwise global variables die
CapsLockDown() {
global CapsLockHeld
global Delay
If (CapsLockHeld == 1) {
Return
}
CapsLockHeld = 1
SetTimer, SendCapsLock, %Delay%
Return
}
CapsLockUp() {
global CapsLockHeld
CapsLockHeld = 0
SetTimer, SendCapsLock, Off
Return
}
我发现一个名为“ Toggler”的旧实用程序(版本为v1.0,日期为2001年1月)对我来说最合适,尽管它有时在Windows 10下似乎已被禁用。它使我可以通过SmartShift函数向CapsLock添加延迟,如果按下Shift键和一个字母,则取消CapsLock的设置。它具有许多其他我不使用的功能。
编者注:看起来开发商Aestas Software可能不再存在,并且该软件自2001年以来似乎未进行过更新。但是,仍可以从http://download.cnet.com/Toggler下载。/3000-2072_4-10054498.html