Page 1 of 1

removed

Posted: 25 Feb 2018, 03:56
by Yaosr
removed

Re: #SingleInstance, Force = what is it

Posted: 25 Feb 2018, 04:29
by Odlanir
From here : https://autohotkey.com/docs/commands/_S ... stance.htm
#SingleInstance : Determines whether a script is allowed to run again when it is already running.
#SingleInstance force|ignore|off
The word FORCE skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload command.

Re: #SingleInstance, Force = what is it

Posted: 25 Feb 2018, 04:40
by Nwb
The docs are glitched at the moment ._.

But yea like odlanir said it prevents two instances of the same script and force replaces the old instance with the new instance

solved

Posted: 25 Feb 2018, 04:42
by Yaosr
solved

Re: #SingleInstance, Force = what is it

Posted: 25 Feb 2018, 06:09
by Nwb
Yaosr wrote:so what is instance in that case? is instance = script ?
Yes. If suppose you have a script running and it sends P every time you click X, and you mistakely open that same script again. When you press P it sends out 2x X. Because there are two scripts.

So that avoids this from happening.

removed

Posted: 25 Feb 2018, 06:56
by Yaosr
removed

solved

Posted: 25 Feb 2018, 07:06
by Yaosr
solved

Re: #SingleInstance, Force = what is it

Posted: 25 Feb 2018, 13:10
by gregster
Yeah, I think (duplicate) hotkey definition in different script instances will just compete - and only one will be triggered. That is not a technique that will work.
But if you have auto-execute sections (including loops and timers) they will run at the same time - in parallel.

Re: #SingleInstance, Force = what is it

Posted: 25 Feb 2018, 13:32
by jeeswg
- You can trigger a hotkey in one script, and get that to trigger other scripts.

Code: Select all

#SingleInstance, off
OnMessage(0x5555, "MsgMonitor")
x:: ;one script to trigger them all
DetectHiddenWindows, On
WinGet, vWinList, List, % A_ScriptFullPath " - AutoHotkey v ahk_class AutoHotkey"
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	if !(hWnd = A_ScriptHwnd)
		PostMessage, 0x5555,,,, % "ahk_id " hWnd
}
;MsgBox, % A_ScriptHwnd
MsgMonitor("", "", "", "")
return

MsgMonitor(wParam, lParam, uMsg, hWnd)
{
	MsgBox, % A_ScriptHwnd
}
- A_ScriptHwnd is the hWnd (window handle) for the script's main window (the one you see when you double-click on the systray icon). Every window/control has a temporary unique number.
- The script demonstrates how you can have multiple scripts all react simultaneously to the same hotkey. Each script does an action (shows a MsgBox), even though only one receives the key press. Since each MsgBox shows a different number, it confirms that each script has been triggered (directly or indirectly) by the hotkey.

- You could also use ~x:: in multiple scripts, they'll all trigger, however, the x key is not suppressed (the active window receives the key press).

Code: Select all

#SingleInstance, off
~x:: ;triggered, not suppressed (open a script multiple times, the key press triggers the subroutine in each instance, however, the key press is not suppressed)
MsgBox, % A_ScriptHwnd
return