opt option value
option - one of these literals: hidden, err, end, waitmsg, clip, waitcpu, slowmouse, slowkeys, keymark, keysync. Error if the specified option does not exist.
value - one of values specified in the table. Default value is 0. To inherit the option from the caller (macro or function that called current function), use value -1. Error if the specified value is not supported.
| option | When QM uses it | value | |
| 0 (default) | other | ||
| hidden | When in macro commands is specified only window name (class is not specified). | Search only visible windows. | 1 - Search all windows. Hidden windows are always searched when class is specified, also with hid-. |
| err | On run-time error. | End macro. | 1 - Continue macro. |
| end | On error, end, etc. Only when in a callback function. Read more in remarks. | End macro softly (clear variables, etc). |
1 - End macro immediately. |
| waitmsg | When waiting (wait, autodelay, etc). Read more in remarks. | Completely block thread execution. | 1 - Allow to receive Windows messages and COM events. 2 - The same as 1, but sets this option for current thread (not only for current function). |
| clip | Clipboard commands (outp, str.getsel, str.setsel). | Preserve (restore) clipboard text. | 1 - Do not preserve clipboard text. |
| waitcpu | Autodelay. Read more in remarks. | Apply only simple autodelay. | 1 - Also apply "wait for CPU" autodelay (Options -> If opt waitcpu ...). |
| slowmouse | Mouse commands. Use to make mouse movements slower, and possibly more reliable in some windows. | Immediately move the mouse pointer to the specified point. | 1 - Slowly move the mouse pointer. The speed depends on the macro speed (spe) and on the distance. |
| slowkeys | key. Use to make it slower and possibly more reliable. | Do not insert delays between keys. Delays may be inserted only if the target window is busy. | 1 - Insert a delay after each key event. The speed depends on the macro speed (spe). Particularly, after each key down and up event is inserted delay equal to autodelay/5. |
| keymark (QM 2.2.0) | key. Read more in remarks. | Use correct scancodes. | 1 - Use modified scancodes. |
| keysync (QM 2.2.1) | key. Use to make it either faster or more reliable. | Use default synchronization method.
The macro waits when sent keys are actually received by the target window. Since there is no completely reliable way to know this, it waits only for a limited time period. It also waits while the window is busy. This method is fast and reliable in most cases. However in certain conditions it may be slower.
In exe, uses method 2 instead. Waiting until the target window actually receives sent keys is not supported in exe, because it is too expensive (uses hooks in dll).
Here "in exe" actually means "in exe, if QM is not running". If QM is running, all synchronization methods work in exe like in QM.
Waiting until the target window actually receives sent keys is not supported if the target window is a console window, except in some cases. Instead is used method 2.
A special synchronization method is used if the target window belongs to the same thread. |
1 - Don't use synchronization. The keys are sent without waiting until the window actually receives them. Fastest. Should not be used if not using low level hooks (unless in exe), because it can create problems with keyboard triggers.
2 - Use minimal synchronization. This method is used by default in exe. The macro only waits while the target window is busy. The synchronization does not work well (keys may be sent too fast) with some windows and in stress conditions (low memory, busy CPU, etc). Slowest in most cases (about 20-100 %). Should not be used if not using low level hooks (unless in exe), because it can create problems with keyboard triggers.
3 - Use maximal synchronization. The macro indefinitely waits until the key is received by the target window. Since there is no completely reliable way to know this, in some windows this can force the macro to wait indefinitely. Therefore this method should not be used in macros designed to work in any window. Exe uses method 2 instead. |
Changes a run-time option locally (only for current instance of running function or macro).
If used as function, opt is identical to getopt (returns current value).
Option opt waitmsg 1 should be used if you use wait commands (explicit or implicit, e.g. autodelay or clipboard commands) in thread (running macro) that has a window (or dialog). While waiting, window must process messages. Without this option, it cannot process messages. This causes various anomalies, such as window not responding, etc. This option also is often necessary when working with COM, especially with events.
Macro that contains opt waitcpu 1 or "wait for CPU" commands, with some processor-hungry programs may run very slowly or produce "wait timeout" errors. Some programs constantly or occasionally use 100% CPU, even when they are ready for input.
To see CPU usage, use Windows Task Manager or perfmon.exe. You can also use GetCPU function.
Option opt end 1 can be used in callback function if an "end macro" command (end, mes-, etc) does not work (it is rare, and can occur if callback's caller handles all exceptions). QM also uses it on run time errors (including end "error"). Ending macro when this option is set may cause memory leak, because local composite variables of callback's caller functions cannot be destroyed. Thread variables are always destroyed. Functions registered by atend are always called.
About opt keymark 1: For keyboard triggers and some other features, QM uses keyboard hooks to intercept keyboard events. QM processes QM-pressed (injected) keys differently than user-pressed (real) keys. For example, a macro cannot trigger a hot-key macro using the key command. However, when the user presses or releases a key simultaneously with the key command, QM processes the key event like generated by the key command (there is no reliable way to distinguish real and injected keys, unless you use low level hook). If it is a trigger-key, the trigger will not work. If it is a wait-key (wait 0 K), the macro will not stop waiting. Also, user-pressed keys may be inserted (typed) between QM-pressed keys. There are two ways to avoid all these problems: 1. Use low level keyboard hook. 2. Insert opt keymark 1 before key. However, when using the second way, some key combinations, e.g. Alt+Num X, will not work as expected. When using low level keyboard hook, opt keymark 1 does not change anything (everything work well with or without it).
See also: hid err end Errors wait outp str.getsel key getopt Options->Run time
Set local run-time option "See hidden windows": opt hidden 1 Set local run-time option "On error resume next": opt err 1