EzFlow997

SpeakCoolDowns

Dec 2nd, 2025 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Autohotkey 3.55 KB | Source Code | 0 0
  1. #Requires AutoHotkey v2.0
  2. #InputLevel 1
  3. #SingleInstance Force
  4. PID := DllCall("GetCurrentProcessId")
  5. ProcessSetPriority "High", PID
  6. A_HotkeyInterval := 0
  7. Hotkey "^1", Exit
  8. Exit(ThisHotkey){
  9.     ExitApp
  10. }
  11.  
  12. global CDS := CoolDownSpeaker()
  13. CDS.ReadCfg()
  14.  
  15. global oVoice := ComObject("SAPI.SpVoice")
  16. oVoice.Rate := -3
  17.  
  18. Hotkey "^2", NewKey
  19. NewKey(ThisHotkey){
  20.     CDS.AddNewKey()
  21. }
  22.  
  23. Hotkey "^3", ShowKeys
  24. ShowKeys(ThisHotkey){
  25.     CDS.ShowKeys()
  26. }
  27.  
  28. Hotkey "^Del", DeleteKey
  29. DeleteKey(ThisHotkey){
  30.     CDS.DeleteKey()
  31. }
  32.  
  33. SetTimer Timers, 10
  34. Timers(){
  35.     CDS.CheckKeyPress()
  36.     CDS.CalculateCoolDowns()
  37. }
  38.  
  39. class CoolDownSpeaker {
  40.     CDS_Keys := []
  41.     KeyTime := []
  42.    
  43.     AddNewKey(){
  44.         Tooltip "Press Key Now"
  45.         key := KeyWaitAny()
  46.         Tooltip
  47.         ;MsgBox Format("{1}", key)
  48.         Speak(key)
  49.         cd := InputBox("Enter cooldown in (ms)", ">").value
  50.         cds_key := Keys()
  51.         cds_key.AddNew(key, cd)
  52.         if(this.CheckExists(cds_key)){
  53.             return
  54.         }
  55.         this.CDS_Keys.Push(cds_key)
  56.         this.WriteCfg()
  57.     }
  58.    
  59.     CheckKeyPress(){
  60.         Loop this.CDS_Keys.Length {
  61.             obj := this.CDS_Keys[A_Index]
  62.             IsDown := GetKeyState(obj.key , "P")
  63.             if(IsDown and !this.CheckKeyAlreadyPressed(obj.key)){
  64.                 keyNow := A_TickCount
  65.                 this.KeyTime.Push([obj.key, obj.cooldown, keyNow])
  66.             }
  67.         }
  68.     }
  69.    
  70.     CheckKeyAlreadyPressed(keyP){
  71.         Loop this.KeyTime.Length {
  72.             obj := this.KeyTime[A_Index]
  73.             key := obj[1]
  74.             if(keyP == key){
  75.                 return True
  76.             }
  77.         }
  78.     }
  79.    
  80.     CalculateCoolDowns(){
  81.         if(this.KeyTime.Length > 0){
  82.             Loop this.KeyTime.Length {
  83.                 obj := this.KeyTime[A_Index]
  84.                 key := obj[1]
  85.                 cooldown := obj[2]
  86.                 keyNow := obj[3]
  87.                 timeNow := A_TickCount
  88.                 if(timeNow - keyNow > cooldown){
  89.                     text := Format("{1}", key)
  90.                     Speak(text)
  91.                     this.KeyTime.RemoveAt(A_Index)
  92.                     break
  93.                 }
  94.             }
  95.         }
  96.     }
  97.    
  98.     DeleteKey(){
  99.         Tooltip "Press Key Now"
  100.         key := KeyWaitAny()
  101.         Tooltip
  102.         ;MsgBox Format("{1}", key)
  103.         Speak(key)
  104.         Loop this.CDS_Keys.Length {
  105.             obj := this.CDS_Keys[A_Index]
  106.             if(obj.key == key){
  107.                 this.CDS_Keys.RemoveAt(A_Index)
  108.                 this.WriteCfg()
  109.                 return True
  110.             }
  111.         }  
  112.     }
  113.    
  114.     CheckExists(cds_key){
  115.         Loop this.CDS_Keys.Length {
  116.             obj := this.CDS_Keys[A_Index]
  117.             if(obj.key == cds_key.key){
  118.                 obj.cooldown := cds_key.cooldown
  119.                 this.CDS_Keys[A_Index] := obj
  120.                 this.WriteCfg()
  121.                 return True
  122.             }
  123.         }
  124.     }
  125.    
  126.     ShowKeys(){
  127.         try{
  128.             Run "CoolDownSpeakerConfig.ini"
  129.         }
  130.     }
  131.    
  132.     WriteCfg(){
  133.         list := ""
  134.         Loop this.CDS_Keys.Length{
  135.             obj := this.CDS_Keys[A_Index]
  136.             key := obj.key
  137.             cd := obj.cooldown
  138.             if(A_Index > 1){
  139.                 list := Format("{1},{2}={3}", list, key, cd)
  140.             }
  141.             else{
  142.                 list := Format("{1}={2}", key, cd)
  143.             }
  144.         }
  145.         IniWrite Format("{1}", list), "CoolDownSpeakerConfig.ini", "Keys", "Keys"
  146.     }
  147.    
  148.     ReadCfg(){
  149.         try{
  150.             this.CDS_Keys := []
  151.             list := IniRead("CoolDownSpeakerConfig.ini", "Keys", "Keys")
  152.             Loop Parse, list, "," {
  153.                 pair := A_LoopField
  154.                 items := []
  155.                 Loop Parse, pair, "=" {
  156.                     ;MsgBox A_LoopField
  157.                     items.Push(A_LoopField)
  158.                 }
  159.                 cds_key := Keys()
  160.                 key := items[1]
  161.                 cd := items[2]
  162.                 cds_key.AddNew(key, cd)
  163.                 this.CDS_Keys.Push(cds_key)
  164.             }
  165.         }
  166.     }
  167. }
  168.  
  169. class Keys {
  170.     key := ""
  171.     cooldown := ""
  172.    
  173.     AddNew(k, cd){
  174.         this.key := k
  175.         this.cooldown := cd
  176.     }
  177. }
  178.  
  179. KeyWaitAny(Options:="")
  180. {
  181.     ih := InputHook(Options)
  182.     if !InStr(Options, "V")
  183.         ih.VisibleNonText := false
  184.     ih.KeyOpt("{All}", "E")  ; End
  185.     ih.Start()
  186.     ih.Wait()
  187.     return ih.EndKey  ; Return the key name
  188. }
  189.  
  190. Speak(text){
  191.     oVoice.Speak(text, 0x1 | 0x2)
  192. }
Advertisement
Add Comment
Please, Sign In to add comment