Cant seem to find/create a script that turns all my scripts on when I press a button (home) and then turn it off when i press the same button again.
Hope someone can help. FYI I just started with ahk yesterday
Thanks in advance
Best Answer Pulover , 18 January 2013 - 02:02 PM
Cant seem to find/create a script that turns all my scripts on when I press a button (home) and then turn it off when i press the same button again.
Hope someone can help. FYI I just started with ahk yesterday
Thanks in advance
It would do something like this: it would have a variable that indicated wheter the scripts are on or not. Then when the button is pushed, it checks the variable and either kills all the scipts or starts them all. It then flips the variable this has been done. Only problem is you would have to add each scipt by hand. If you need help, the tutorial show how to do this.
killing scripts != suspending hotkeys + pausing scripts
I think killing is less preferred.
And there is also a way to not add each script by hand: actually you could scan process list, define autohotkey.exe processes and the ahk-files they are bound to and then send commands to those processes.
But it will be quite hard for a complete newbie.
Actually, there is no need to write your own bicycle, you can search for "AHKControl by Lexikos" script and it already contains a way to scan memory for running *.ahk files, just use his code.
WM_COMMAND := 0x111 CMD_RELOAD := 65400 CMD_EDIT := 65401 CMD_PAUSE := 65403 CMD_SUSPEND := 65404 DetectHiddenWindows, On Process, Exist this_pid := ErrorLevel control_id := WinExist("ahk_class AutoHotkey ahk_pid " this_pid) ; Press Home to toggle Pause & Suspend state for all scripts. Home:: WinGet, id, list, ahk_class AutoHotkey Loop, %id% { this_id := id%A_Index% If (this_id <> control_id) { PostMessage, WM_COMMAND, CMD_PAUSE,,, ahk_id %this_id% PostMessage, WM_COMMAND, CMD_SUSPEND,,, ahk_id %this_id% } } return
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls
Join the New AutoHotkey Forum!
Pulover, thanks for the neat code, but could you explain why everyone specifies first things like
WM_COMMAND := 0x111 CMD_RELOAD := 65400 CMD_EDIT := 65401 CMD_PAUSE := 65403 CMD_SUSPEND := 65404
? Aren't those codes static? Why not someone write a patch for ahk to make it natively understand commands like "WM_COMMAND", so users won't have to use unreadable "0x1111" instead?
I tested and it works perfectly. However, can this code be modified so that if a script is already paused or suspended, then it is not affected (that is, it is not turned back unpaused or unsuspended in this case and remain in its initial state of pause or suspend) so that this script acts ONLY on unpaused or unsuspended scripts?
WM_COMMAND := 0x111 CMD_RELOAD := 65400 CMD_EDIT := 65401 CMD_PAUSE := 65403 CMD_SUSPEND := 65404 DetectHiddenWindows, On Process, Exist this_pid := ErrorLevel control_id := WinExist("ahk_class AutoHotkey ahk_pid " this_pid) ; Press Home to toggle Pause & Suspend state for all scripts. Home:: Toggle := !Toggle WinGet, id, list, ahk_class AutoHotkey Loop, %id% { this_id := id%A_Index% If (this_id <> control_id) { If (ScriptStatus(this_id, "Paused") = !Toggle) PostMessage, WM_COMMAND, CMD_PAUSE,,, ahk_id %this_id% If (ScriptStatus(this_id, "Suspended") = !Toggle) PostMessage, WM_COMMAND, CMD_SUSPEND,,, ahk_id %this_id% } } return ScriptStatus(script_id, cmd) { SendMessage, 0x211,,,, ahk_id %script_id% ; WM_ENTERMENULOOP SendMessage, 0x212,,,, ahk_id %script_id% ; WM_EXITMENULOOP mainMenu := DllCall("GetMenu", "uint", script_id) fileMenu := DllCall("GetSubMenu", "uint", mainMenu, "int", 0) isPaused := DllCall("GetMenuState", "uint", fileMenu, "uint", 4, "uint", 0x400) >> 3 & 1 isSuspended := DllCall("GetMenuState", "uint", fileMenu, "uint", 5, "uint", 0x400) >> 3 & 1 DllCall("CloseHandle", "uint", fileMenu) DllCall("CloseHandle", "uint", mainMenu) If (cmd = "Paused") return isPaused If (cmd = "Suspended") return isSuspended }
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls
Join the New AutoHotkey Forum!
~Pause::Suspend
Probably the easiest solution of all: If you add this hotkey to all scripts, pressing the Pause key will Suspend all scripts~Pause::Suspend
If you add
pause::pause
to every script it will only pause and unpause the first script that responds. If you have it suspend, then pressing the button multiple times will eventualy suspend all, but suspending then turns off hotkeys so you would have to manualy unsuspend each one.
Thanks, Pulover, it works flawlessly. Sorry to come back again for anther request. Is it possible for the script to remember the initial state of a script (pause, for example) so that after the toggle, it does not turn it back to unpause but to its previous state of pause (if it was paused before running the toggle script)? Pause -> Suspend -> Pause || Normal -> Suspend -> Normal
... to every script it will only pause and unpause the first script that responds. If you have it suspend, then pressing the button multiple times will eventualy suspend all, but suspending then turns off hotkeys so you would have to manualy unsuspend each one.
If (ScriptStatus(this_id, "Paused") = !Toggle)
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls
Join the New AutoHotkey Forum!
Perferct, sorry for not being clear. I hardly ever use Suspend. So disabling the line If (ScriptStatus(this_id, "Paused") = !Toggle) is perfect for Pause -> Suspend -> Pause || Normal -> Suspend -> Normal
I hardly suspend any scripts but if I did, by disabling the above line, I get Suspend -> Suspend -> Normal. If the previous state was Suspend, how can I keep that state so that I get: Suspend -> Suspend -> Suspend (and not Suspend -> Suspend -> Normal)? Thanks
Now I'm even more confused... If you remove the statement for Pause it does not affect the behavior for suspend so if the script is suspended it will remain suspended on first execution and unsuspended on the next one.
Suspended Scripts: Suspend > Normal > Suspend Unsuspended Scripts: Suspend > Normal > Suspend Paused Scripts: Normal > Paused > Normal Unpaused Scripts: Paused > Normal > Paused
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls
Join the New AutoHotkey Forum!