Advertisement
Lateralus138

Script Toggler For AutoHotkey

Jun 14th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; This old script is here to archive and a quick reference for me   ;
  3. ; a rewrite is in the works                                         ;
  4. ; This script toggles hotkeys and/or suspends AutoHotkey scripts and;
  5. ; programs by hotkeys or by system tray.                            ;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7. _title:="AutoHotkey Script Toggler"
  8. Menu,Tray,NoStandard
  9. Menu, Tray, Add, %_title%, TitleInfo
  10. Menu, Tray, Add
  11. Menu, Tray, Add, Suspend Hotkeys, Hotkeys
  12. Menu, Tray, Add, Pause Scripts, Scripts
  13. Menu, Tray, Add, Toggle Both All Scripts, Both
  14. Menu, Tray, Add
  15. Menu, Tray, Add, Help, Help
  16. Menu, Tray, Add
  17. Menu, Tray, Add, Exit, Close
  18. If A_IsCompiled
  19.     Menu, Tray, Icon, %_title%, %A_ScriptFullPath%,1
  20. Else
  21.     Menu, Tray, Icon, %_title%, shell32.dll, 138
  22. Menu, Tray, Icon, Help, shell32.dll, 24
  23. Menu, Tray, Icon, Suspend Hotkeys, shell32.dll, 216
  24. Menu, Tray, Icon, Pause Scripts, shell32.dll, 216
  25. Menu, Tray, Icon, Toggle Both All Scripts, shell32.dll, 216
  26. Menu, Tray, Icon, Exit,shell32.dll, 216
  27. SetBatchLines,-1
  28. #ScrollLock::Gosub, Scripts
  29. #Pause::Gosub, Hotkeys
  30. #PrintScreen::Gosub, Both
  31. ToggleScripts(state:="Pause",name:=0,exception:=0){
  32.     mode:=(name And exception)?2:name?1:0
  33.     If ! state:=(InStr(state,"pause") Or state=65306)?65306
  34.         :(InStr(state,"suspend") Or state=65305)?65305
  35.         :0 {
  36.             MsgBox,16,%A_ThisFunc% Error,   %   "Improper toggle state passed into variable: state"
  37.                                             .   "`nE.g.: " A_ThisFunc "() - defaults to " A_ThisFunc "(""Pause"")"
  38.                                             .   "`n`nPossible options: "
  39.                                             .   "`nPause script/s:" A_Tab """Pause"" or 65306"
  40.                                             .   "`nSuspend script/s:" A_Tab """Suspend"" or 65305"
  41.             Return
  42.         }
  43.     DetectHiddenWindows On
  44.     WinGet, id_list, List, ahk_class AutoHotkey
  45.     Loop, %id_list%
  46.         {
  47.             this_id := id_list%A_Index%
  48.             If (mode=2) {
  49.                     WinGetTitle,this_title,ahk_id %this_id%
  50.                     If IsObject(name){
  51.                         For index, fname in name {
  52.                                 If InStr(this_title,fname) {
  53.                                         nBreak:=1
  54.                                         Break
  55.                                 } Else nBreak:=0
  56.                         }
  57.                     } Else {
  58.                         If InStr(this_title,name) {
  59.                                 nBreak:=1
  60.                         } Else nBreak:=0
  61.                     }
  62.                 }
  63.             If nBreak
  64.                 Continue
  65.             If  (mode=1) {
  66.                 WinGetTitle,this_title,ahk_id %this_id%
  67.                 If IsObject(name){
  68.                     For index, fname in name {
  69.                         If InStr(this_title,fname)
  70.                             PostMessage, 0x111, %state%,,, ahk_id %this_id%
  71.                     }
  72.                 } Else {
  73.                     If InStr(this_title,name)
  74.                         PostMessage, 0x111, %state%,,, ahk_id %this_id%        
  75.                 }
  76.             }
  77.                 Else
  78.                     PostMessage, 0x111, %state%,,, ahk_id %this_id%
  79.         }
  80.     DetectHiddenWindows, Off
  81. }
  82. TitleInfo:
  83.     MsgBox,64,%_title% Info,%_title% by Ian Pride 2017`naka Lateralus138 aka FluxApex
  84. Return
  85. Hotkeys:
  86.     ToggleScripts("Suspend",A_ScriptName,1)
  87.     If tog:=!tog {
  88.         If A_IsCompiled
  89.             Menu, Tray, Icon, Suspend Hotkeys, %A_ScriptFullPath%,1
  90.         Else
  91.             Menu, Tray, Icon, Suspend Hotkeys, shell32.dll, 138
  92.         Menu, Tray, Rename,  Suspend Hotkeys,Resume Hotkeys
  93.     } Else {
  94.         Menu, Tray, Icon, Resume Hotkeys, shell32.dll, 216
  95.         Menu, Tray, Rename,Resume Hotkeys, Suspend Hotkeys
  96.     }
  97. Return
  98. Scripts:
  99.     ToggleScripts(,A_ScriptName,1)
  100.     If tog2:=!tog2 {
  101.         If A_IsCompiled
  102.             Menu, Tray, Icon, Pause Scripts, %A_ScriptFullPath%,1
  103.         Else
  104.             Menu, Tray, Icon, Pause Scripts, shell32.dll, 138
  105.         Menu, Tray, Rename,  Pause Scripts,Un-Pause Scripts
  106.     } Else {
  107.         Menu, Tray, Icon, Un-Pause Scripts, shell32.dll, 216
  108.         Menu, Tray, Rename,Un-Pause Scripts, Pause Scripts
  109.     }
  110. Return
  111. Both:
  112.     Gosub,Hotkeys
  113.     Gosub,Scripts
  114. Return
  115. Help:
  116.     MsgBox,64,%_title% Help,    %   "Disable/enable script and hotkeys in all other AutoHotkey"
  117.                                 .   "`nprograms and scripts."
  118.                                 .   "`n`nHotkeys:"
  119.                                 .   "`nWindows Key+ScrollLock:" A_Tab "Suspend/Resume Hotkeys"
  120.                                 .   "`nWindows Key+Pause:" A_Tab "Pause/Un-Pause Scripts"
  121.                                 .   "`nWindows Key+PrintScreen:" A_Tab "Toggle Both For all"
  122.                                 .   "`n`nCan also be toggled from the system tray menu."
  123. Return
  124. Close:
  125.     ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement