UseWindowRegEx

Windows management function.

The UseWindowRegEx function specifies the window to which subsequent keyboard, mouse and menu actions are directed, using Regular Expressions to specify the window title part of the window name. Not available in WinTask Lite.

Usage

UseWindow is used to bring to foreground/front the specified window so that it may receive keystrokes, mouse clicks and other interactive actions. If the exact window name is not found at replay, a fuzzy match is tried, truncating the rightmost characters until the specified window name is found. UseWindowRegEx extends the fuzzy match and can trigger on a sub-string within the window title. Regular expressions are text patterns that are used for window title matching.

Syntax

UseWindowRegEx(<window_name> [,<instance>[,NoActivate]])
or
ret=UseWindowRegEx(<window_name> [,<instance>[,NoActivate]])

Parameters

<window_name>, string. window name (see this topic) of the window to which script actions will be directed. You can use the SPY tool to manually determine the caption of a window. During Recording mode they will be inserted automatically. The Regular expressions can be used to specify the title part of the window name, for example if in "NOTEPAD.EXE|Edit|20.txt - Notepad" 20 is a day number which changes every day, UseWindowRegEx("NOTEPAD.EXE|Edit|[0-9][0-9].* - Notepad") triggers on a window title whatever day number in it.

<instance>, optional parameter, instance number of the window.

WinTask will try to find the window defined by UseWindowRegEx for a period of time defined by the system variable #ActionTimeout. Once the window is found, WinTask makes it active and sends all actions to it. We recommend to set #UseExact at 1 when using a Regular Expression.

The keyword NoActivate prevents the window from being activated ; this keyword is generated automatically when Low level Recording mode is used. In this case, the statements following UseWindowRegEx will activate the window - thus it is not necessary to activate it beforehand.

Return value

Ret, numeric return code. When the <window_name> has been found and can be activated, the function returns 0, otherwise use this return code for Error Handling.

Remarks

We describe below the most common cases.

Character

Description

Examples

.

Matches a single character

a.r matches a0r, air, a£r,...

*

Repeats the previous character zero or several times

abc* matches ab, abc, abcc, abccc, ...

+

Repeats the previous character one or several times

abc+ matches abc, abcc, abccc, ...

?

Makes the preceding character optional

abc? matches ab or abc

|

Alternation, regular expression equivalent of OR

200[6|7] matches 2006 or 2007

[]

Matches one out of several characters

gr[ae]y matches gray, grey but not graey

{n}

Repeats n times the previous character

a{3} matches aaa

{n,m}

Repeats the previous character between n and m times

a{2,4} matches aa, aaa, aaaa

[ - ]

Matches one out of a range of several characters

gr[0-9]y matches gr0y, gr1y, ... gr9y but not gr19y

[ ^ - ]

Excludes the range of several characters

gr[^0-9]y matches gray, grby, grcy, ... grzy but not gr0y, gr1y,... gr9y

 ^

Outside a [, matches at the start of the string

^begin matches begin, beginning, begin with

$

Matches at the end of the string

end$ matches end, will end, at the end

\charact.

A backslash escapes special characters above their meaning

\+ matches + (and so the + sign does not have its special meaning)

During execution, if the target window is minimized, it is automatically restored and activated.

See also

#UseExact, UseWindowHandle, Window name

Examples

We list below the most common cases

Single character
Keys have to be sent to the notepad window whatever character is after Doc

#UseExact=1
UseWindowRegEx("NOTEPAD.EXE|Edit|Doc. - Notepad|1")

SendKeys("Hello")

Triggers for any window Doca, Docb, ..., Doc0, Doc1, ....

Single character in a list
Keys have to be sent to the notepad window if, after Doc, the year is 2005, 2006 or 2007

#UseExact=1
UseWindowRegEx("NOTEPAD.EXE|Edit|Doc200[567] - Notepad|1")

SendKeys("Hello")

Triggers for any window Doc2005, Doc2006, or Doc2007

Single character NOT in a list
Keys have to be sent to the notepad window if, after Doc, the year is NOT 2005, 2006 or 2007

#UseExact=1
UseWindowRegEx("NOTEPAD.EXE|Edit|Doc200[^567] - Notepad|1")

SendKeys("Hello")

Triggers for any window Doc2000, Doc2001, Doc2002, Doc2003, Doc2004, Doc2008, Doc2009 and Doc200a, Doc200b, ...Doc200[, Doc200), ...

Single character within a range
Keys have to be sent to the notepad window if, after Doc, it can be any year in the 1990s

#UseExact=1
UseWindowRegEx("NOTEPAD.EXE|Edit|Doc199[0-9] - Notepad|1")

SendKeys("Hello")

Triggers for any window Doc1990, Doc1991,..., Doc1999