Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey v2.0
- #InputLevel 1
- #SingleInstance Force
- PID := DllCall("GetCurrentProcessId")
- ProcessSetPriority "High", PID
- A_HotkeyInterval := 0
- Hotkey "^1", Exit
- Exit(ThisHotkey){
- ExitApp
- }
- global CDS := CoolDownSpeaker()
- CDS.ReadCfg()
- global oVoice := ComObject("SAPI.SpVoice")
- oVoice.Rate := -3
- Hotkey "^2", NewKey
- NewKey(ThisHotkey){
- CDS.AddNewKey()
- }
- Hotkey "^3", ShowKeys
- ShowKeys(ThisHotkey){
- CDS.ShowKeys()
- }
- Hotkey "^Del", DeleteKey
- DeleteKey(ThisHotkey){
- CDS.DeleteKey()
- }
- SetTimer Timers, 10
- Timers(){
- CDS.CheckKeyPress()
- CDS.CalculateCoolDowns()
- }
- class CoolDownSpeaker {
- CDS_Keys := []
- KeyTime := []
- AddNewKey(){
- Tooltip "Press Key Now"
- key := KeyWaitAny()
- Tooltip
- ;MsgBox Format("{1}", key)
- Speak(key)
- cd := InputBox("Enter cooldown in (ms)", ">").value
- cds_key := Keys()
- cds_key.AddNew(key, cd)
- if(this.CheckExists(cds_key)){
- return
- }
- this.CDS_Keys.Push(cds_key)
- this.WriteCfg()
- }
- CheckKeyPress(){
- Loop this.CDS_Keys.Length {
- obj := this.CDS_Keys[A_Index]
- IsDown := GetKeyState(obj.key , "P")
- if(IsDown and !this.CheckKeyAlreadyPressed(obj.key)){
- keyNow := A_TickCount
- this.KeyTime.Push([obj.key, obj.cooldown, keyNow])
- }
- }
- }
- CheckKeyAlreadyPressed(keyP){
- Loop this.KeyTime.Length {
- obj := this.KeyTime[A_Index]
- key := obj[1]
- if(keyP == key){
- return True
- }
- }
- }
- CalculateCoolDowns(){
- if(this.KeyTime.Length > 0){
- Loop this.KeyTime.Length {
- obj := this.KeyTime[A_Index]
- key := obj[1]
- cooldown := obj[2]
- keyNow := obj[3]
- timeNow := A_TickCount
- if(timeNow - keyNow > cooldown){
- text := Format("{1}", key)
- Speak(text)
- this.KeyTime.RemoveAt(A_Index)
- break
- }
- }
- }
- }
- DeleteKey(){
- Tooltip "Press Key Now"
- key := KeyWaitAny()
- Tooltip
- ;MsgBox Format("{1}", key)
- Speak(key)
- Loop this.CDS_Keys.Length {
- obj := this.CDS_Keys[A_Index]
- if(obj.key == key){
- this.CDS_Keys.RemoveAt(A_Index)
- this.WriteCfg()
- return True
- }
- }
- }
- CheckExists(cds_key){
- Loop this.CDS_Keys.Length {
- obj := this.CDS_Keys[A_Index]
- if(obj.key == cds_key.key){
- obj.cooldown := cds_key.cooldown
- this.CDS_Keys[A_Index] := obj
- this.WriteCfg()
- return True
- }
- }
- }
- ShowKeys(){
- try{
- Run "CoolDownSpeakerConfig.ini"
- }
- }
- WriteCfg(){
- list := ""
- Loop this.CDS_Keys.Length{
- obj := this.CDS_Keys[A_Index]
- key := obj.key
- cd := obj.cooldown
- if(A_Index > 1){
- list := Format("{1},{2}={3}", list, key, cd)
- }
- else{
- list := Format("{1}={2}", key, cd)
- }
- }
- IniWrite Format("{1}", list), "CoolDownSpeakerConfig.ini", "Keys", "Keys"
- }
- ReadCfg(){
- try{
- this.CDS_Keys := []
- list := IniRead("CoolDownSpeakerConfig.ini", "Keys", "Keys")
- Loop Parse, list, "," {
- pair := A_LoopField
- items := []
- Loop Parse, pair, "=" {
- ;MsgBox A_LoopField
- items.Push(A_LoopField)
- }
- cds_key := Keys()
- key := items[1]
- cd := items[2]
- cds_key.AddNew(key, cd)
- this.CDS_Keys.Push(cds_key)
- }
- }
- }
- }
- class Keys {
- key := ""
- cooldown := ""
- AddNew(k, cd){
- this.key := k
- this.cooldown := cd
- }
- }
- KeyWaitAny(Options:="")
- {
- ih := InputHook(Options)
- if !InStr(Options, "V")
- ih.VisibleNonText := false
- ih.KeyOpt("{All}", "E") ; End
- ih.Start()
- ih.Wait()
- return ih.EndKey ; Return the key name
- }
- Speak(text){
- oVoice.Speak(text, 0x1 | 0x2)
- }
Advertisement
Add Comment
Please, Sign In to add comment