First of all, Era, I don't see how your snippet from the first post could have the effect that you expect - I also never encountered the problem, neither on Win10 nor elsewhere. But anyway, let's say the problem exists (on your system) - your code cannot fix it, I am sure.
directives only affect hotkey
s and hotstring
s and make them context-sensitive
. If you put normal code between them, it will be run once (if it is part of an auto-execute section or a subroutine) or multiple times (if part of a SetTimer
, subroutine or loop
etc.). But the #if
directives will have no effect at all on this.
It looks, by the code provided by you, that theClick...
code is only executed (at max) once when you start your script - ignoring the #If
directives altogether which are not relevant here, since there is no hotkey or hotstring between them. How can this achieve the effect you want (every time sending the click, when a file explorer is active, I assume)?!?
swagfag on the other hand, uses a timer to constantly check, every 50 milliseconds, if a File Explorer
window is active.
If you don't believe me, run this script (at first, with no explorer open):
Code: Select all
#If WinActive("ahk_class CabinetWClass")
msgbox Explorer really active ???
It will show the msgbox, even if there is no file explorer window. Because I made it #persistent, it is still running. Now open an explorer window and...
nothing happens, no msgbox shows.
Secondly, I think this is a misperception:
I've noticed that lots of AHK scripts begin with certain directives like #SingleInstance Force and SetTitleMatchMode 2. So wouldn't it be helpful if a few of these nearly universal commands were just baked into AHK itself? They would just be assumed behavior of all scripts (the way ! stands for ALT), thus not required to be specified in each new script? And if for some reason you do need to turn the behavior off, you could then type it in (such as -#SingleInstance Force, or SetTitleMatchMode 0).
You don't need any of these directives or commands (which are setting options) to code a perfectly working AHK script. These are still only options
. All these directives like #SingleInstance
or commands like SetTitleMatchMode
have a default value or behaviour that is described in the docs - if you are fine with the default, no need to change or even mention it in the script.
For example, for SetTitleMatchMode
you can find the following in the docs: "If unspecified, TitleMatchMode defaults to 1 and fast." 1
is listed as: "A window's title must start with the specified WinTitle to be a match."
And for #SingleInstance
A script containing hotkeys, hotstrings, #Persistent, OnMessage(), or Gui is single-instance (dialog & prompt) by default. Other scripts default to allowing multiple instances. [...]
This directive is ignored when any of the following command line switches are used: /force /f /restart /r
Of course, there are a lot of options (that's how AHK can easily do lots of things) - but there are always default options (most make sense, changing them would break older scripts) - I have several scripts running where I don't specify any directive. In short, this behaviour that you wish, already exists. The default options might not be your preferred ones, though, but there... we can't help