Home > FAQ > Useful Basic Tasks when writing a script > How do I find the window which has the focus?

Controlling Script Execution Speed

Speed while typing

Sendkeys function simulates a user typing in the window specified in the UseWindow function. How fast is done this typing depends on #SendKeysDelay value ; maximum speed can be reached by setting the system variable #SendKeysDelay to -10. Be aware that typing too fast can saturate the keyboard buffer.

Typing can be slow too, because every Sendkeys is preceeded by a Usewindow statement. This occurs in forms where each individual field is in fact one specific window (instead of one window for the whole form and its fields). In that case, Recording mode generates first a Usewindow and then a Sendkeys in that specific field. You can use NoActivate option in Sendkeys function and delete the Usewindow preceeding the Sendkeys : the string passed by Sendkeys statement will then be typed in the window and field where the text cursor is, without any wait or verification.
 

UseWindow function executes slowly

By default, at replay, if the exact window name specified in the script is not found, WinTask x64 looks for a window with a similar name (fuzzy-match search mode); this default behavior avoids the error message "window not found" at replay. The system variable #UseExact allows to specify if you want to use the exact search (#UseExact=1) or the approached search (#UseExact=0, default value).

In fuzzy-match mode (approached search), WinTask x64 first looks for a window with the exact same window name, or at least for a window whose name has the same executable module and the same first characters for the window class as the one specified in the script. If no such match is found within 3,33 seconds, WinTask x64 looks for a window with a name just starting with the same characters as the one specified in the script. This value, 3 seconds, is 1/9 of the value of the system variable #ActionTimeout. So, you can change this delay by modifying #ActionTimeout value.

To summarize, when at replay the window name is different from the recorded or written one, the most efficient approach is manually to truncate the window name. For instance, if the recorded UseWindow statement is :
UseWindow("WINWORD.EXE|OpusApp|Microsoft Word - Referenc.doc",1)
Truncate the window name to:
UseWindow("WINWORD.EXE|OpusApp|Microsoft Word",1)
Then at replay, WinTask x64 will find any Word window, whatever document is loaded.

Remember that you can truncate window title and window class (except the first character of window class).

Finally, the Spy module is very useful for finding window names.