Saya punya dua skrip AHK di sini. Jika Anda ingin saya menjelaskan lebih jauh dari apa yang saya komentari dalam skrip, silakan tambahkan komentar di bawah ini.
Yang pertama lebih kompleks dan mungkin cenderung gagal, tetapi mengirimkan CapsLock sebagai penekanan tombol literal setelah ditahan selama satu detik.
Yang kedua mengubah status "Caps Lock", yang mungkin tidak diinginkan jika alasan Anda ingin penundaan itu untuk tombol pintas CapsLock beberapa program lain.
Anda dapat mengkonfigurasi penundaan dengan mengubah Delay
variabel di baris kedua.
Mengirim penekanan tombol literal "CapsLock"
; 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
}
Mengalihkan status "Caps Lock":
; 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
}