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