Updated few things on the script.

This commit is contained in:
Umiko 2025-05-02 19:35:13 +07:00
parent d90e95bed0
commit a2d061584f
2 changed files with 69 additions and 41 deletions

BIN
capsLockSounds.ini Normal file

Binary file not shown.

View File

@ -1,112 +1,131 @@
#Persistent ; Keep the script running #Persistent
SoundBeep, 300, 250 SoundBeep, 300, 250
capsLockOn := false capsLockOn := false
iniFile := "capsLockSounds.ini" iniFile := "capsLockSounds.ini"
SetTimer, CheckCapsLock, 50 ; Check the CapsLock status every 50 milliseconds SetTimer, CheckCapsLockStatus, 50
if (FileExist(iniFile)) { if (FileExist(iniFile)) {
IniRead, offSound, %iniFile%, SoundFiles, OffSound IniRead, offSound, %iniFile%, SoundFiles, OffSound
IniRead, onSound, %iniFile%, SoundFiles, OnSound IniRead, onSound, %iniFile%, SoundFiles, OnSound
IniRead, loopSound, %iniFile%, SoundFiles, LoopSound IniRead, loopSound, %iniFile%, SoundFiles, LoopSound
IniRead, timerInterval, %iniFile%, Settings, TimerInterval IniRead, timerInterval, %iniFile%, Settings, TimerInterval
; Ensure timer interval is not below 2 seconds
if (timerInterval < 2000) if (timerInterval < 2000)
timerInterval := 2000 timerInterval := 2000
} }
; Hotkey to terminate the script with Ctrl + Shift + X /**
* Hotkey to terminate the script with Ctrl + Shift + X
*/
^+x:: ^+x::
PlayExitSound() PlayExitSoundEffect()
ExitApp ExitApp
return return
PlayExitSound() { /**
* Play exit sound effect before terminating
*/
PlayExitSoundEffect() {
notes := [500, 550, 600] notes := [500, 550, 600]
for _, note in notes { for _, note in notes {
SoundBeep, note, 200 SoundBeep, note, 200
Sleep 150 Sleep 150
} }
} }
CheckCapsLock: /**
* Check the CapsLock status and play sounds
*/
CheckCapsLockStatus:
If (GetKeyState("CapsLock", "T") && !capsLockOn) { If (GetKeyState("CapsLock", "T") && !capsLockOn) {
capsLockOn := true capsLockOn := true
SetTimer, BeepEvery10Seconds, %TimerInterval% SetTimer, LoopCapsLockSound, %TimerInterval%
SoundPlay, %onSound% SoundPlay, %onSound%
} else if (!GetKeyState("CapsLock", "T") && capsLockOn) { } else if (!GetKeyState("CapsLock", "T") && capsLockOn) {
capsLockOn := false capsLockOn := false
SetTimer, BeepEvery10Seconds, Off SetTimer, LoopCapsLockSound, Off
SoundPlay, %offSound% SoundPlay, %offSound%
} }
Return Return
BeepEvery10Seconds: /**
* Play looping sound when CapsLock is on
*/
LoopCapsLockSound:
If (capsLockOn && loopSound != "") { If (capsLockOn && loopSound != "") {
SoundPlay, %loopSound% SoundPlay, %loopSound%
} }
Return Return
; Hotkey to display the GUI for selecting sound files /**
* Hotkey to show GUI for selecting sound files
*/
^!+s:: ^!+s::
Gui, Add, Text,, Insert the path for the sound when you turn your CapsLock off here: Gui, Add, Text,, Insert the path for the sound when you turn your CapsLock off here:
Gui, Add, Edit, x10 y10 w300 vOffSound, %offSound% Gui, Add, Edit, x10 y10 w300 vOffSound, %offSound%
Gui, Add, Button, x320 y10 w80 gBrowseOffSound, Browse Gui, Add, Button, x320 y10 w80 gBrowseOffSoundFile, Browse
Gui, Add, Button, x410 y10 w70 gPreviewOffSound, Preview Gui, Add, Button, x410 y10 w70 gPreviewOffSoundFile, Preview
Gui, Add, Text,, Insert the path for the sound when you turn your CapsLock on here: Gui, Add, Text,, Insert the path for the sound when you turn your CapsLock on here:
Gui, Add, Edit, x10 y40 w300 vOnSound, %onSound% Gui, Add, Edit, x10 y40 w300 vOnSound, %onSound%
Gui, Add, Button, x320 y40 w80 gBrowseOnSound, Browse Gui, Add, Button, x320 y40 w80 gBrowseOnSoundFile, Browse
Gui, Add, Button, x410 y40 w70 gPreviewOnSound, Preview Gui, Add, Button, x410 y40 w70 gPreviewOnSoundFile, Preview
Gui, Add, Text,, Insert the path for the sound when the CapsLock is on here: Gui, Add, Text,, Insert the path for the looping sound when CapsLock is on here:
Gui, Add, Edit, x10 y70 w300 vLoopSound, %loopSound% Gui, Add, Edit, x10 y70 w300 vLoopSound, %loopSound%
Gui, Add, Button, x320 y70 w80 gBrowseLoopSound, Browse Gui, Add, Button, x320 y70 w80 gBrowseLoopSoundFile, Browse
Gui, Add, Button, x410 y70 w70 gPreviewLoopSound, Preview Gui, Add, Button, x410 y70 w70 gPreviewLoopSoundFile, Preview
Gui, Add, Text,, type (In Ms) your timer for looping your sound here: noted it should be not less than 2000ms or 2sec Gui, Add, Text,, Type (in ms) your timer for looping your sound here (must be >= 2000 ms):
Gui, Add, Edit, x10 y100 w100 vTimerInterval, %timerInterval% Gui, Add, Edit, x10 y100 w100 vTimerInterval, %timerInterval%
Gui, Add, Text, x120 y100, Timer Interval (ms) Gui, Add, Text, x120 y100, Timer Interval (ms)
Gui, Add, Button, x150 y130 w100 h30 gSaveSounds, Save Gui, Add, Button, x150 y130 w100 h30 gSaveSoundSettings, Save
Gui, Add, Button, x100 y130 w100 h30 gCancel, Cancel Gui, Add, Button, x100 y130 w100 h30 gCancelSettings, Cancel
Gui, Show, , Select Sounds Gui, Show, , Select Sounds
return return
; Browse button for selecting the sound file when CapsLock is off /**
BrowseOffSound: * Browse for the sound file when CapsLock is off
*/
BrowseOffSoundFile:
FileSelectFile, offSound, 1, , Select a sound file when CapsLock is off, Audio Files (*.wav; *.mp3) FileSelectFile, offSound, 1, , Select a sound file when CapsLock is off, Audio Files (*.wav; *.mp3)
GuiControl,, OffSound, %offSound% GuiControl,, OffSound, %offSound%
return return
; Browse button for selecting the sound file when CapsLock is on /**
BrowseOnSound: * Browse for the sound file when CapsLock is on
*/
BrowseOnSoundFile:
FileSelectFile, onSound, 1, , Select a sound file when CapsLock is on, Audio Files (*.wav; *.mp3) FileSelectFile, onSound, 1, , Select a sound file when CapsLock is on, Audio Files (*.wav; *.mp3)
GuiControl,, OnSound, %onSound% GuiControl,, OnSound, %onSound%
return return
; Browse button for selecting the sound file for looping when CapsLock is on /**
BrowseLoopSound: * Browse for the looping sound file
*/
BrowseLoopSoundFile:
FileSelectFile, loopSound, 1, , Select a sound file for looping when CapsLock is on, Audio Files (*.wav; *.mp3) FileSelectFile, loopSound, 1, , Select a sound file for looping when CapsLock is on, Audio Files (*.wav; *.mp3)
GuiControl,, LoopSound, %loopSound% GuiControl,, LoopSound, %loopSound%
return return
; Save button to save the selected sound files and timer interval /**
SaveSounds: * Save selected sound files and timer interval to INI file
; Save the selected sound file paths and timer interval to the INI file */
SaveSoundSettings:
IniWrite, %offSound%, %iniFile%, SoundFiles, OffSound IniWrite, %offSound%, %iniFile%, SoundFiles, OffSound
IniWrite, %onSound%, %iniFile%, SoundFiles, OnSound IniWrite, %onSound%, %iniFile%, SoundFiles, OnSound
IniWrite, %loopSound%, %iniFile%, SoundFiles, LoopSound IniWrite, %loopSound%, %iniFile%, SoundFiles, LoopSound
GuiControlGet, timerInterval,, TimerInterval GuiControlGet, timerInterval,, TimerInterval
; Ensure timer interval is not below 2 seconds
if (timerInterval < 2000) { if (timerInterval < 2000) {
timerInterval := 10000 timerInterval := 10000
MsgBox, Timer duration should not be below 2000ms or 2 seconds. Timer set to 10seconds. MsgBox, Timer duration should not be below 2000ms or 2 seconds. Timer set to 10 seconds.
} }
IniWrite, %timerInterval%, %iniFile%, Settings, TimerInterval IniWrite, %timerInterval%, %iniFile%, Settings, TimerInterval
MsgBox, configuration saved.. MsgBox, Configuration saved.
Gui, Destroy Gui, Destroy
return return
; Preview button functionality /**
PreviewOffSound: * Preview the selected off sound
*/
PreviewOffSoundFile:
GuiControlGet, offSound, , OffSound GuiControlGet, offSound, , OffSound
if (offSound = "") { if (offSound = "") {
MsgBox, File path is empty. MsgBox, File path is empty.
@ -117,7 +136,10 @@ PreviewOffSound:
} }
return return
PreviewOnSound: /**
* Preview the selected on sound
*/
PreviewOnSoundFile:
GuiControlGet, onSound, , OnSound GuiControlGet, onSound, , OnSound
if (onSound = "") { if (onSound = "") {
MsgBox, File path is empty. MsgBox, File path is empty.
@ -128,7 +150,10 @@ PreviewOnSound:
} }
return return
PreviewLoopSound: /**
* Preview the selected looping sound
*/
PreviewLoopSoundFile:
GuiControlGet, loopSound, , LoopSound GuiControlGet, loopSound, , LoopSound
if (loopSound = "") { if (loopSound = "") {
MsgBox, File path is empty. MsgBox, File path is empty.
@ -139,6 +164,9 @@ PreviewLoopSound:
} }
return return
Cancel: /**
* Cancel and close the GUI
*/
CancelSettings:
Gui, Destroy Gui, Destroy
return return