Debian Codegraph @

docs/X11-GUITest.html

raw
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>X11::GUITest - Provides GUI testing/interaction routines.</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:root@localhost" />
8 </head>
9
10 <body>
11
12
13
14 <ul id="index">
15 <li><a href="#NAME">NAME</a></li>
16 <li><a href="#VERSION">VERSION</a></li>
17 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
18 <li><a href="#DEPENDENCIES">DEPENDENCIES</a></li>
19 <li><a href="#INSTALLATION">INSTALLATION</a></li>
20 <li><a href="#INSTALLATION-NOTES">INSTALLATION NOTES</a></li>
21 <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
22 <li><a href="#WAYLAND-NOTES">WAYLAND NOTES</a></li>
23 <li><a href="#FUNCTIONS">FUNCTIONS</a></li>
24 <li><a href="#OTHER-DOCUMENTATION">OTHER DOCUMENTATION</a></li>
25 <li><a href="#COPYRIGHT">COPYRIGHT</a></li>
26 <li><a href="#AUTHOR">AUTHOR</a></li>
27 <li><a href="#CONTRIBUTORS">CONTRIBUTORS</a></li>
28 <li><a href="#CREDITS">CREDITS</a></li>
29 </ul>
30
31 <h1 id="NAME">NAME</h1>
32
33 <p>X11::GUITest - Provides GUI testing/interaction routines.</p>
34
35 <h1 id="VERSION">VERSION</h1>
36
37 <p>0.29</p>
38
39 <p>Updates are made available at the following sites:</p>
40
41 <pre><code>http\://sourceforge.net/projects/x11guitest
42 http\://www.cpan.org</code></pre>
43
44 <p>Please consult &#39;Changes&#39; for the list of changes between module revisions.</p>
45
46 <h1 id="DESCRIPTION">DESCRIPTION</h1>
47
48 <p>This Perl package is intended to facilitate the testing of GUI applications by means of user emulation. It can be used to test/interact with GUI applications; which have been built upon the X library or toolkits (i.e., GTK+, Xt, Qt, Motif, etc.) that &quot;wrap&quot; the X library&#39;s functionality.</p>
49
50 <p>A basic recorder (x11guirecord) is also available, and can be found in the source code repository.</p>
51
52 <h1 id="DEPENDENCIES">DEPENDENCIES</h1>
53
54 <p>An X server with the XTest extensions enabled. This seems to be the norm. If it is not enabled, it usually can be by modifying the X server configuration (i.e., XF86Config).</p>
55
56 <p>This module talks to the X server via the standard DISPLAY environment variable, exactly like any other X11 client. By default DISPLAY is usually &quot;:0.0&quot; (the local machine). To target a different X server -- for example, one on a remote host -- set DISPLAY before running your script:</p>
57
58 <pre><code>export DISPLAY=&lt;hostname-or-ipaddress&gt;:&lt;display&gt;.&lt;screen&gt;</code></pre>
59
60 <p>Under most circumstances, xhost will also need to be run on the remote host to permit the connection.</p>
61
62 <p>DISPLAY only helps if there is an actual X11 server to point it at. This module requires a real X11 server -- either a native X11 session, or XWayland running as an X11 compatibility layer inside a Wayland session. It cannot function under a pure Wayland session with no XWayland present. See WAYLAND NOTES below for how to diagnose and work around this on a Wayland desktop.</p>
63
64 <p>There is a known incompatibility between the XTest and Xinerama extensions, which causes the XTestFakeMotionEvent() function to misbehave when the Xinerama (X server) extension is active. MoveMouseAbs() has an alternate, XWarpPointer()-based implementation for this case, but it is not enabled by default -- it requires rebuilding with the X11_GUITEST_USING_XINERAMA preprocessor macro defined *in addition to* this module&#39;s other defines (a DEFINE= override on the command line replaces the whole value, it does not add to it):</p>
65
66 <pre><code>perl Makefile.PL DEFINE=&quot;-DNDEBUG -DX11_GUITEST_ALT_L_FALLBACK_META_L -DX11_GUITEST_USING_XINERAMA&quot;
67 make
68 make install</code></pre>
69
70 <p>Only do this if Xinerama is actually active on the target X server; otherwise leave the module at its default build.</p>
71
72 <p>The optional x11guirecord recorder utility (see &#39;recorder/&#39; and INSTALLATION below) additionally requires the X server&#39;s RECORD extension. This is separate from XTest, and while common, isn&#39;t guaranteed to be present/enabled on every X server -- particularly minimal or older commercial X implementations.</p>
73
74 <h1 id="INSTALLATION">INSTALLATION</h1>
75
76 <pre><code>perl Makefile.PL
77 make
78 make test
79 make install
80
81 # If &quot;make install&quot; fails with a permissions error, see INSTALLATION
82 # NOTES below.
83
84 # If the build has errors, you may need to install the following dependencies:
85 # libxt-dev, libxtst-dev
86
87 # If you&#39;d like to install the recorder, use these steps:
88 cd recorder
89 ./autogen.sh
90 ./configure
91 make
92 make install
93 x11guirecord --help
94
95 # See INSTALLATION NOTES below if this &quot;make install&quot; fails with a
96 # permissions error too.
97
98 # The recorder has its own build-time dependencies, separate from the
99 # above:
100 # autoconf, automake (needed to run autogen.sh)
101 # popt development files (e.g. popt-devel, libpopt-dev)
102 # libX11, libXtst development files, if not already installed
103 # for the main module above
104 #
105 # GNU gettext (libintl.h) is optional -- if it isn&#39;t found, the recorder
106 # builds without translation support rather than failing. This is
107 # relevant mainly on AIX and HP-UX, which don&#39;t provide GNU gettext
108 # natively.</code></pre>
109
110 <h1 id="INSTALLATION-NOTES">INSTALLATION NOTES</h1>
111
112 <p><code>make install</code> writes into your Perl&#39;s installation directories (e.g. <code>site_perl</code> under <i>/usr/lib/perl5</i> or <i>/usr/local</i>). If that location isn&#39;t writable by your user -- the common case for a system Perl -- rerun the last step as <code>sudo make install</code>. Perl setups that install to a user-writable location instead (<code>local::lib</code>, perlbrew, plenv, etc.) normally don&#39;t need <code>sudo</code>. If you&#39;re not sure which applies, try plain <code>make install</code> first and only add <code>sudo</code> if it fails with a permissions error.</p>
113
114 <p>The same applies to the recorder&#39;s <code>make install</code> step.</p>
115
116 <h1 id="SYNOPSIS">SYNOPSIS</h1>
117
118 <p>For additional examples, please look under the &#39;eg/&#39; sub-directory from the installation folder.</p>
119
120 <pre><code>use X11::GUITest qw/
121 StartApp
122 WaitWindowViewable
123 SendKeys
124 /;
125
126 # Start gedit application
127 # Note: The interface for this example application keeps changing.
128 StartApp(&#39;gedit&#39;);
129
130 # Wait for application window to come up and become viewable.
131 my ($GEditWinId) = WaitWindowViewable(&#39;Untitled Document 1&#39;);
132 if (!$GEditWinId) {
133 die(&quot;Couldn&#39;t find gedit window in time!&quot;);
134 }
135
136 # Send text to it
137 SendKeys(&quot;Hello, how are you?\n&quot;);
138
139 # Close Application (Alt-f, q).
140 SendKeys(&#39;%(f)q&#39;);
141
142 # Handle gedit&#39;s Question window if it comes up when closing. Wait
143 # at most 5 seconds for it.
144 if (WaitWindowViewable(&#39;Question&#39;, undef, 5)) {
145 # Don&#39;t Save (Alt-n)
146 SendKeys(&#39;%(n)&#39;);
147 }</code></pre>
148
149 <h1 id="WAYLAND-NOTES">WAYLAND NOTES</h1>
150
151 <p>Even under XWayland, be aware that Wayland&#39;s per-application isolation model prevents synthetic input (sent via the XTest extension, which this module relies on) from reaching native Wayland clients -- only X11/XWayland-rooted windows will respond to it. This is a deliberate security property of the Wayland protocol, not a bug, and there is no compile-time or runtime workaround. See https://www.linuxteck.com/x11-vs-wayland/ for background on the X11 vs. Wayland input model.</p>
152
153 <p>On a Wayland session (check with &#39;echo $XDG_SESSION_TYPE&#39;), most applications default to running as native Wayland clients, invisible to this module no matter what DISPLAY is set to. Forcing a specific application through XWayland instead is usually enough to fix that. Which environment variable to set depends on the GUI toolkit the target application is built with:</p>
154
155 <pre><code>Toolkit Variable to set Example
156 ------- --------------- -------
157 GTK (GNOME, etc.) GDK_BACKEND=x11 GDK_BACKEND=x11 gedit &amp;
158 Qt / KDE Plasma QT_QPA_PLATFORM=xcb QT_QPA_PLATFORM=xcb dolphin &amp;</code></pre>
159
160 <p>Two gotchas that can make this appear not to work, regardless of toolkit:</p>
161
162 <ul>
163
164 <li><p>Many apps use single-instance activation (GTK&#39;s GApplication or KDE&#39;s KDBusService, both implemented over D-Bus). If the application is already running, a new invocation with the variable set just signals the existing (Wayland) process to open a window -- it does not start a new, X11-backed process. Fully quit the application first (i.e., confirm no process is running), then relaunch it.</p>
165
166 </li>
167 <li><p>Flatpak-packaged applications (increasingly the default for some apps on Fedora) do not automatically inherit environment variables from the host shell. Use &#39;flatpak run --env=GDK_BACKEND=x11 &lt;app-id&gt;&#39; (substitute QT_QPA_PLATFORM=xcb for Qt/KDE apps) instead of GDK_BACKEND=x11 &lt;app&gt; &amp;, and use &#39;flatpak list --app&#39; to find the app id if it&#39;s not obvious from the command name.</p>
168
169 </li>
170 </ul>
171
172 <p>If neither works, or you need this reliably for many applications, the more robust fix is a session-level one: log out and choose an X11 session at the login screen, if your desktop still offers one -- e.g. &quot;GNOME on Xorg&quot; or &quot;Plasma (X11)&quot; (some recent GNOME/Fedora releases have deprecated or removed that option).</p>
173
174 <h1 id="FUNCTIONS">FUNCTIONS</h1>
175
176 <p>Parameters enclosed within [] are optional.</p>
177
178 <p>If there are multiple optional parameters available for a function and you would like to specify the last one, for example, you can utilize undef for those parameters you don&#39;t specify.</p>
179
180 <p>REGEX in the documentation below denotes an item that is treated as a regular expression. For example, the regex &quot;^OK$&quot; would look for an exact match for the word OK.</p>
181
182 <dl>
183
184 <dt id="FindWindowLike-TITLEREGEX-WINDOWIDSTARTUNDER">FindWindowLike TITLEREGEX [, WINDOWIDSTARTUNDER]</dt>
185 <dd>
186
187 <p>Finds the window Ids of the windows matching the specified title regex. Optionally one can specify the window to start under; which would allow one to constrain the search to child windows of that window.</p>
188
189 <p>An array of window Ids is returned for the matches found. An empty array is returned if no matches were found.</p>
190
191 <pre><code>my @WindowIds = FindWindowLike(&#39;gedit&#39;);
192 # Only worry about first window found
193 my ($WindowId) = FindWindowLike(&#39;gedit&#39;);</code></pre>
194
195 </dd>
196 </dl>
197
198 <dl>
199
200 <dt id="WaitWindowLike-TITLEREGEX-WINDOWIDSTARTUNDER-MAXWAITINSECONDS">WaitWindowLike TITLEREGEX [, WINDOWIDSTARTUNDER] [, MAXWAITINSECONDS]</dt>
201 <dd>
202
203 <p>Waits for a window to come up that matches the specified title regex. Optionally one can specify the window to start under; which would allow one to constrain the search to child windows of that window.</p>
204
205 <p>One can optionally specify an alternative wait amount in seconds. A window will keep being looked for that matches the specified title regex until this amount of time has been reached. The default amount is defined in the DEF_WAIT constant available through the \:CONST export tag.</p>
206
207 <p>If a window is going to be manipulated by input, WaitWindowViewable is the more robust solution to utilize.</p>
208
209 <p>An array of window Ids is returned for the matches found. An empty array is returned if no matches were found.</p>
210
211 <pre><code>my @WindowIds = WaitWindowLike(&#39;gedit&#39;);
212 # Only worry about first window found
213 my ($WindowId) = WaitWindowLike(&#39;gedit&#39;);
214
215 WaitWindowLike(&#39;gedit&#39;) or die(&quot;gedit window not found!&quot;);</code></pre>
216
217 </dd>
218 </dl>
219
220 <dl>
221
222 <dt id="WaitWindowViewable-TITLEREGEX-WINDOWIDSTARTUNDER-MAXWAITINSECONDS">WaitWindowViewable TITLEREGEX [, WINDOWIDSTARTUNDER] [, MAXWAITINSECONDS]</dt>
223 <dd>
224
225 <p>Similar to WaitWindow, but only recognizes windows that are viewable. When GUI applications are started, their window isn&#39;t necessarily viewable yet, let alone available for input, so this function is very useful.</p>
226
227 <p>Likewise, this function will only return an array of the matching window Ids for those windows that are viewable. An empty array is returned if no matches were found.</p>
228
229 </dd>
230 </dl>
231
232 <dl>
233
234 <dt id="WaitWindowClose-WINDOWID-MAXWAITINSECONDS">WaitWindowClose WINDOWID [, MAXWAITINSECONDS]</dt>
235 <dd>
236
237 <p>Waits for the specified window to close.</p>
238
239 <p>One can optionally specify an alternative wait amount in seconds. The window will keep being checked to see if it has closed until this amount of time has been reached. The default amount is defined in the DEF_WAIT constant available through the \:CONST export tag.</p>
240
241 <p>zero is returned if window is not gone, non-zero if it is gone.</p>
242
243 </dd>
244 </dl>
245
246 <dl>
247
248 <dt id="WaitSeconds-SECONDS">WaitSeconds SECONDS</dt>
249 <dd>
250
251 <p>Pauses execution for the specified amount of seconds.</p>
252
253 <pre><code>WaitSeconds(0.5); # Wait 1/2 second
254 WaitSeconds(3); # Wait 3 seconds</code></pre>
255
256 </dd>
257 </dl>
258
259 <dl>
260
261 <dt id="ClickWindow-WINDOWID-X-Offset-Y-Offset-Button">ClickWindow WINDOWID [, X Offset] [, Y Offset] [, Button]</dt>
262 <dd>
263
264 <p>Clicks on the specified window with the mouse.</p>
265
266 <p>Optionally one can specify the X offset and Y offset. By default, the top left corner of the window is clicked on, with these two parameters one can specify a different position to be clicked on.</p>
267
268 <p>One can also specify an alternative button. The default button is M_LEFT, but M_MIDDLE and M_RIGHT may be specified too. Also, you could use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3, M_BTN4, M_BTN5. These are all available through the \:CONST export tag.</p>
269
270 <p>zero is returned on failure, non-zero for success</p>
271
272 </dd>
273 </dl>
274
275 <dl>
276
277 <dt id="GetWindowsFromPid-PID">GetWindowsFromPid PID</dt>
278 <dd>
279
280 <p>Returns a list of window ids discovered for the specified process id (pid).</p>
281
282 <p>undef is returned on error.</p>
283
284 </dd>
285 </dl>
286
287 <dl>
288
289 <dt id="GetWindowFromPoint-X-Y-SCREEN">GetWindowFromPoint X, Y [, SCREEN]</dt>
290 <dd>
291
292 <p>Returns the window that is at the specified point. If no screen is given, it is taken from the value given when opening the X display.</p>
293
294 <p>zero is returned if there are no matches (i.e., off screen).</p>
295
296 </dd>
297 </dl>
298
299 <dl>
300
301 <dt id="IsChild-PARENTWINDOWID-WINDOWID">IsChild PARENTWINDOWID, WINDOWID</dt>
302 <dd>
303
304 <p>Determines if the specified window is a child of the specified parent.</p>
305
306 <p>zero is returned for false, non-zero for true.</p>
307
308 </dd>
309 </dl>
310
311 <dl>
312
313 <dt id="QuoteStringForSendKeys-STRING">QuoteStringForSendKeys STRING</dt>
314 <dd>
315
316 <p>Quotes {} characters in the specified string that would be interpreted as having special meaning if sent to SendKeys directly. This function would be useful if you had a text file in which you wanted to use each line of the file as input to the SendKeys function, but didn&#39;t want any special interpretation of the characters in the file.</p>
317
318 <p>Returns the quoted string, undef is returned on error.</p>
319
320 <pre><code># Quote ~, %, etc. as {~}, {%}, etc for literal use in SendKeys.
321 SendKeys( QuoteStringForSendKeys(&#39;Hello: ~%^(){}+#&#39;) );
322 SendKeys( QSfSK(&#39;#+#&#39;) );</code></pre>
323
324 <p>The international AltGr key - modifier character (&amp;) is not escaped by this function. Escape this character manually (&quot;{&amp;}&quot;), if used/needed.</p>
325
326 </dd>
327 </dl>
328
329 <dl>
330
331 <dt id="StartApp-COMMANDLINE">StartApp COMMANDLINE</dt>
332 <dd>
333
334 <p>Starts a program directly using exec. This function returns after checking that the child process remains running. Useful for starting GUI /applications and then going on to work with them.</p>
335
336 <p>zero is returned on failure, non-zero for success</p>
337
338 <pre><code>StartApp(&#39;gedit&#39;);</code></pre>
339
340 <p>Environment variable assignments (e.g. GDK_BACKEND=x11, may be needed to force a GTK application through XWayland instead of native Wayland -- see DEPENDENCIES above) can be prefixed onto COMMANDLINE, provided the whole thing is passed as a single string:</p>
341
342 <pre><code>StartApp(&#39;GDK_BACKEND=x11 gedit&#39;); # Works.
343 StartApp(&#39;GDK_BACKEND=x11&#39;, &#39;gedit&#39;); # Does NOT work.</code></pre>
344
345 </dd>
346 </dl>
347
348 <dl>
349
350 <dt id="RunApp-COMMANDLINE">RunApp COMMANDLINE</dt>
351 <dd>
352
353 <p>Uses the shell to execute a program until its completion.</p>
354
355 <p>Return value will be application specific, however -1 is returned to indicate a failure in starting the program.</p>
356
357 <pre><code>RunApp(&#39;/work/myapp&#39;);</code></pre>
358
359 </dd>
360 </dl>
361
362 <dl>
363
364 <dt id="ClickMouseButton-BUTTON">ClickMouseButton BUTTON</dt>
365 <dd>
366
367 <p>Clicks the specified mouse button. Available mouse buttons are: M_LEFT, M_MIDDLE, M_RIGHT, M_DOWN, M_UP. Also, you could use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3, M_BTN4, M_BTN5. These are all available through the \:CONST export tag.</p>
368
369 <p>zero is returned on failure, non-zero for success.</p>
370
371 </dd>
372 </dl>
373
374 <dl>
375
376 <dt id="DefaultScreen">DefaultScreen</dt>
377 <dd>
378
379 <p>Returns the screen number specified in the X display value used to open the display.</p>
380
381 <p>Leverages the Xlib macro of the same name.</p>
382
383 </dd>
384 </dl>
385
386 <dl>
387
388 <dt id="ScreenCount">ScreenCount</dt>
389 <dd>
390
391 <p>Returns the number of screens in the X display specified when opening it.</p>
392
393 <p>Leverages the Xlib macro of the same name.</p>
394
395 </dd>
396 </dl>
397
398 <dl>
399
400 <dt id="SetEventSendDelay-DELAYINMILLISECONDS">SetEventSendDelay DELAYINMILLISECONDS</dt>
401 <dd>
402
403 <p>Sets the milliseconds of delay between events being sent to the X display. It is usually not a good idea to set this to 0.</p>
404
405 <p>Please note that this delay will also affect SendKeys.</p>
406
407 <p>Returns the old delay amount in milliseconds.</p>
408
409 </dd>
410 </dl>
411
412 <dl>
413
414 <dt id="GetEventSendDelay">GetEventSendDelay</dt>
415 <dd>
416
417 <p>Returns the current event sending delay amount in milliseconds.</p>
418
419 </dd>
420 </dl>
421
422 <dl>
423
424 <dt id="SetKeySendDelay-DELAYINMILLISECONDS">SetKeySendDelay DELAYINMILLISECONDS</dt>
425 <dd>
426
427 <p>Sets the milliseconds of delay between keystrokes.</p>
428
429 <p>Returns the old delay amount in milliseconds.</p>
430
431 </dd>
432 </dl>
433
434 <dl>
435
436 <dt id="GetKeySendDelay">GetKeySendDelay</dt>
437 <dd>
438
439 <p>Returns the current keystroke sending delay amount in milliseconds.</p>
440
441 </dd>
442 </dl>
443
444 <dl>
445
446 <dt id="GetWindowName-WINDOWID">GetWindowName WINDOWID</dt>
447 <dd>
448
449 <p>Returns the window name for the specified window Id. undef is returned if name could not be obtained.</p>
450
451 <pre><code># Return the name of the window that has the input focus.
452 my $WinName = GetWindowName(GetInputFocus());</code></pre>
453
454 </dd>
455 </dl>
456
457 <dl>
458
459 <dt id="GetWindowPid-WINDOWID">GetWindowPid WINDOWID</dt>
460 <dd>
461
462 <p>Returns the process id (pid) associated with the specified window. 0 is returned if the pid is not available.</p>
463
464 <pre><code># Return the pid of the window that has the input focus.
465 my $pid = GetWindowPid(GetInputFocus());</code></pre>
466
467 </dd>
468 </dl>
469
470 <dl>
471
472 <dt id="SetWindowName-WINDOWID-NAME">SetWindowName WINDOWID, NAME</dt>
473 <dd>
474
475 <p>Sets the window name for the specified window Id.</p>
476
477 <p>zero is returned on failure, non-zero for success.</p>
478
479 </dd>
480 </dl>
481
482 <dl>
483
484 <dt id="GetRootWindow-SCREEN">GetRootWindow [SCREEN]</dt>
485 <dd>
486
487 <p>Returns the Id of the root window of the screen. This is the top/root level window that all other windows are under. If no screen is given, it is taken from the value given when opening the X display.</p>
488
489 </dd>
490 </dl>
491
492 <dl>
493
494 <dt id="GetChildWindows-WINDOWID">GetChildWindows WINDOWID</dt>
495 <dd>
496
497 <p>Returns an array of the child windows for the specified window Id. If it detects that the window hierarchy is in transition, it will wait half a second and try again.</p>
498
499 </dd>
500 </dl>
501
502 <dl>
503
504 <dt id="MoveMouseAbs-X-Y-SCREEN">MoveMouseAbs X, Y [, SCREEN]</dt>
505 <dd>
506
507 <p>Moves the mouse cursor to the specified absolute position in the optionally given screen. If no screen is given, it is taken from the value given when opening the X display.</p>
508
509 <p>Zero is returned on failure, non-zero for success.</p>
510
511 </dd>
512 </dl>
513
514 <dl>
515
516 <dt id="GetMousePos">GetMousePos</dt>
517 <dd>
518
519 <p>Returns an array containing the position and the screen (number) of the mouse cursor.</p>
520
521 <pre><code>my ($x, $y, $scr_num) = GetMousePos();</code></pre>
522
523 </dd>
524 </dl>
525
526 <dl>
527
528 <dt id="PressMouseButton-BUTTON">PressMouseButton BUTTON</dt>
529 <dd>
530
531 <p>Presses the specified mouse button. Available mouse buttons are: M_LEFT, M_MIDDLE, M_RIGHT, M_DOWN, M_UP. Also, you could use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3, M_BTN4, M_BTN5. These are all available through the \:CONST export tag.</p>
532
533 <p>zero is returned on failure, non-zero for success.</p>
534
535 </dd>
536 </dl>
537
538 <dl>
539
540 <dt id="ReleaseMouseButton-BUTTON">ReleaseMouseButton BUTTON</dt>
541 <dd>
542
543 <p>Releases the specified mouse button. Available mouse buttons are: M_LEFT, M_MIDDLE, M_RIGHT, M_DOWN, M_UP. Also, you could use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3, M_BTN4, M_BTN5. These are all available through the \:CONST export tag.</p>
544
545 <p>zero is returned on failure, non-zero for success.</p>
546
547 </dd>
548 </dl>
549
550 <dl>
551
552 <dt id="SendKeys-KEYS">SendKeys KEYS</dt>
553 <dd>
554
555 <p>Sends keystrokes to the window that has the input focus.</p>
556
557 <p>The keystrokes to send are those specified in KEYS parameter. Some characters have special meaning, they are:</p>
558
559 <pre><code>Modifier Keys:
560 ^ CTRL
561 % ALT
562 + SHIFT
563 # META
564 &amp; ALTGR
565
566 Other Keys:
567 ~ ENTER
568 \n ENTER
569 \t TAB
570 ( and ) MODIFIER GROUPING
571 { and } QUOTE / ESCAPE CHARACTERS</code></pre>
572
573 <p>Simply, one can send a text string like so:</p>
574
575 <pre><code>SendKeys(&#39;Hello, how are you today?&#39;);</code></pre>
576
577 <p>Parenthesis allow a modifier to work on one or more characters. For example:</p>
578
579 <pre><code>SendKeys(&#39;%(f)q&#39;); # Alt-f, then press q
580 SendKeys(&#39;%(fa)^(m)&#39;); # Alt-f, Alt-a, Ctrl-m
581 SendKeys(&#39;+(abc)&#39;); # Uppercase ABC using shift modifier
582 SendKeys(&#39;^(+(l))&#39;); # Ctrl-Shift-l
583 SendKeys(&#39;+&#39;); # Press shift</code></pre>
584
585 <p>Braces are used to quote special characters, for utilizing aliased key names, or for special functionality. Multiple characters can be specified in a brace by space delimiting the entries. Characters can be repeated using a number that is space delimited after the preceding key.</p>
586
587 <p>Quote Special Characters</p>
588
589 <pre><code>SendKeys(&#39;{{}&#39;); # {
590 SendKeys(&#39;{+}&#39;); # +
591 SendKeys(&#39;{#}&#39;); # #
592
593 You can also use QuoteStringForSendKeys (QSfSK) to perform quoting.</code></pre>
594
595 <p>Aliased Key Names</p>
596
597 <pre><code>SendKeys(&#39;{BAC}&#39;); # Backspace
598 SendKeys(&#39;{F1 F2 F3}&#39;); # F1, F2, F3
599 SendKeys(&#39;{TAB 3}&#39;); # Press TAB 3 times
600 SendKeys(&#39;{SPC 3 a b c}&#39;); # Space 3 times, a, b, c</code></pre>
601
602 <p>Special Functionality</p>
603
604 <pre><code># Pause execution for 500 milliseconds
605 SendKeys(&#39;{PAUSE 500}&#39;);</code></pre>
606
607 <p>Combinations</p>
608
609 <pre><code>SendKeys(&#39;abc+(abc){TAB PAUSE 500}&#39;); # a, b, c, A, B, C, Tab, Pause 500
610 SendKeys(&#39;+({a b c})&#39;); # A, B, C</code></pre>
611
612 <p>The following abbreviated key names are currently recognized within a brace set. If you don&#39;t see the desired key, you can still use the unabbreviated name for the key. If you are unsure of this name, utilize the xev (X event view) tool, press the key you want and look at the tools output for the name of that key. Names that are in the list below can be utilized regardless of case. Ones that aren&#39;t in this list are going to be case sensitive and also not abbreviated. For example, using &#39;xev&#39; you will find that the name of the backspace key is BackSpace, so you could use {BackSpace} in place of {bac} if you really wanted to.</p>
613
614 <pre><code>Name Action
615 -------------------
616 BAC BackSpace
617 BS BackSpace
618 BKS BackSpace
619 BRE Break
620 CAN Cancel
621 CAP Caps_Lock
622 DEL Delete
623 DOWN Down
624 END End
625 ENT Return
626 ESC Escape
627 F1 F1
628 ... ...
629 F12 F12
630 HEL Help
631 HOM Home
632 INS Insert
633 LAL Alt_L
634 LMA Meta_L
635 LCT Control_L
636 LEF Left
637 LSH Shift_L
638 LSK Super_L
639 MNU Menu
640 NUM Num_Lock
641 PGD Page_Down
642 PGU Page_Up
643 PRT Print
644 RAL Alt_R
645 RMA Meta_R
646 RCT Control_R
647 RIG Right
648 RSH Shift_R
649 RSK Super_R
650 SCR Scroll_Lock
651 SPA Space
652 SPC Space
653 TAB Tab
654 UP Up</code></pre>
655
656 <p>zero is returned on failure, non-zero for success. For configurations (Xvfb) that don&#39;t support Alt_Left, Meta_Left is automatically used in its place.</p>
657
658 </dd>
659 </dl>
660
661 <dl>
662
663 <dt id="PressKey-KEY">PressKey KEY</dt>
664 <dd>
665
666 <p>Presses the specified key.</p>
667
668 <p>One can utilize the abbreviated key names from the table listed above as outlined in the following example:</p>
669
670 <pre><code># Alt-n
671 PressKey(&#39;LAL&#39;); # Left Alt
672 PressKey(&#39;n&#39;);
673 ReleaseKey(&#39;n&#39;);
674 ReleaseKey(&#39;LAL&#39;);
675
676 # Uppercase a
677 PressKey(&#39;LSH&#39;); # Left Shift
678 PressKey(&#39;a&#39;);
679 ReleaseKey(&#39;a&#39;);
680 ReleaseKey(&#39;LSH&#39;);</code></pre>
681
682 <p>The ReleaseKey calls in the above example are there to set both key states back.</p>
683
684 <p>zero is returned on failure, non-zero for success.</p>
685
686 </dd>
687 </dl>
688
689 <dl>
690
691 <dt id="ReleaseKey-KEY">ReleaseKey KEY</dt>
692 <dd>
693
694 <p>Releases the specified key. Normally follows a PressKey call.</p>
695
696 <p>One can utilize the abbreviated key names from the table listed above.</p>
697
698 <pre><code>ReleaseKey(&#39;n&#39;);</code></pre>
699
700 <p>zero is returned on failure, non-zero for success.</p>
701
702 </dd>
703 </dl>
704
705 <dl>
706
707 <dt id="PressReleaseKey-KEY">PressReleaseKey KEY</dt>
708 <dd>
709
710 <p>Presses and releases the specified key.</p>
711
712 <p>One can utilize the abbreviated key names from the table listed above.</p>
713
714 <pre><code>PressReleaseKey(&#39;n&#39;);</code></pre>
715
716 <p>This function is affected by the key send delay.</p>
717
718 <p>zero is returned on failure, non-zero for success.</p>
719
720 </dd>
721 </dl>
722
723 <dl>
724
725 <dt id="IsKeyPressed-KEY">IsKeyPressed KEY</dt>
726 <dd>
727
728 <p>Determines if the specified key is currently being pressed.</p>
729
730 <p>You can specify such things as &#39;bac&#39; or the unabbreviated form &#39;BackSpace&#39; as covered in the SendKeys information. Brace forms such as &#39;{bac}&#39; are unsupported. A &#39;{&#39; is taken literally and letters are case sensitive.</p>
731
732 <pre><code>if (IsKeyPressed(&#39;esc&#39;)) { # Is Escape pressed?
733 if (IsKeyPressed(&#39;a&#39;)) { # Is a pressed?
734 if (IsKeyPressed(&#39;A&#39;)) { # Is A pressed?</code></pre>
735
736 <p>Returns non-zero for true, zero for false.</p>
737
738 </dd>
739 </dl>
740
741 <dl>
742
743 <dt id="IsMouseButtonPressed-BUTTON">IsMouseButtonPressed BUTTON</dt>
744 <dd>
745
746 <p>Determines if the specified mouse button is currently being pressed.</p>
747
748 <p>Available mouse buttons are: M_LEFT, M_MIDDLE, M_RIGHT. Also, you could use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3, M_BTN4, M_BTN5. These are all available through the \:CONST export tag.</p>
749
750 <pre><code>if (IsMouseButtonPressed(M_LEFT)) { # Is left button pressed?</code></pre>
751
752 <p>Returns non-zero for true, zero for false.</p>
753
754 </dd>
755 </dl>
756
757 <dl>
758
759 <dt id="IsWindow-WINDOWID">IsWindow WINDOWID</dt>
760 <dd>
761
762 <p>zero is returned if the specified window Id is not for something that can be recognized as a window. non-zero is returned if it looks like a window.</p>
763
764 </dd>
765 </dl>
766
767 <dl>
768
769 <dt id="IsWindowViewable-WINDOWID">IsWindowViewable WINDOWID</dt>
770 <dd>
771
772 <p>zero is returned if the specified window Id is for a window that isn&#39;t viewable. non-zero is returned if the window is viewable.</p>
773
774 </dd>
775 </dl>
776
777 <dl>
778
779 <dt id="IsWindowCursor-WINDOWID-CURSOR">IsWindowCursor WINDOWID, CURSOR</dt>
780 <dd>
781
782 <p>Determines if the specified window has the specified cursor.</p>
783
784 <p>zero is returned for false, non-zero for true.</p>
785
786 <p>The following cursors are available through the \:CONST export tag.</p>
787
788 <pre><code>Name
789 -------------------
790 XC_NUM_GLYPHS
791 XC_X_CURSOR
792 XC_ARROW
793 XC_BASED_ARROW_DOWN
794 XC_BASED_ARROW_UP
795 XC_BOAT
796 XC_BOGOSITY
797 XC_BOTTOM_LEFT_CORNER
798 XC_BOTTOM_RIGHT_CORNER
799 XC_BOTTOM_SIDE
800 XC_BOTTOM_TEE
801 XC_BOX_SPIRAL
802 XC_CENTER_PTR
803 XC_CIRCLE
804 XC_CLOCK
805 XC_COFFEE_MUG
806 XC_CROSS
807 XC_CROSS_REVERSE
808 XC_CROSSHAIR
809 XC_DIAMOND_CROSS
810 XC_DOT
811 XC_DOTBOX
812 XC_DOUBLE_ARROW
813 XC_DRAFT_LARGE
814 XC_DRAFT_SMALL
815 XC_DRAPED_BOX
816 XC_EXCHANGE
817 XC_FLEUR
818 XC_GOBBLER
819 XC_GUMBY
820 XC_HAND1
821 XC_HAND2
822 XC_HEART
823 XC_ICON
824 XC_IRON_CROSS
825 XC_LEFT_PTR
826 XC_LEFT_SIDE
827 XC_LEFT_TEE
828 XC_LEFTBUTTON
829 XC_LL_ANGLE
830 XC_LR_ANGLE
831 XC_MAN
832 XC_MIDDLEBUTTON
833 XC_MOUSE
834 XC_PENCIL
835 XC_PIRATE
836 XC_PLUS
837 XC_QUESTION_ARROW
838 XC_RIGHT_PTR
839 XC_RIGHT_SIDE
840 XC_RIGHT_TEE
841 XC_RIGHTBUTTON
842 XC_RTL_LOGO
843 XC_SAILBOAT
844 XC_SB_DOWN_ARROW
845 XC_SB_H_DOUBLE_ARROW
846 XC_SB_LEFT_ARROW
847 XC_SB_RIGHT_ARROW
848 XC_SB_UP_ARROW
849 XC_SB_V_DOUBLE_ARROW
850 XC_SHUTTLE
851 XC_SIZING
852 XC_SPIDER
853 XC_SPRAYCAN
854 XC_STAR
855 XC_TARGET
856 XC_TCROSS
857 XC_TOP_LEFT_ARROW
858 XC_TOP_LEFT_CORNER
859 XC_TOP_RIGHT_CORNER
860 XC_TOP_SIDE
861 XC_TOP_TEE
862 XC_TREK
863 XC_UL_ANGLE
864 XC_UMBRELLA
865 XC_UR_ANGLE
866 XC_WATCH
867 XC_XTERM</code></pre>
868
869 </dd>
870 </dl>
871
872 <dl>
873
874 <dt id="MoveWindow-WINDOWID-X-Y">MoveWindow WINDOWID, X, Y</dt>
875 <dd>
876
877 <p>Moves the window to the specified location.</p>
878
879 <p>zero is returned on failure, non-zero for success.</p>
880
881 </dd>
882 </dl>
883
884 <dl>
885
886 <dt id="ResizeWindow-WINDOWID-WIDTH-HEIGHT">ResizeWindow WINDOWID, WIDTH, HEIGHT</dt>
887 <dd>
888
889 <p>Resizes the window to the specified size.</p>
890
891 <p>zero is returned on failure, non-zero for success.</p>
892
893 </dd>
894 </dl>
895
896 <dl>
897
898 <dt id="IconifyWindow-WINDOWID">IconifyWindow WINDOWID</dt>
899 <dd>
900
901 <p>Minimizes (Iconifies) the specified window.</p>
902
903 <p>zero is returned on failure, non-zero for success.</p>
904
905 </dd>
906 </dl>
907
908 <dl>
909
910 <dt id="UnIconifyWindow-WINDOWID">UnIconifyWindow WINDOWID</dt>
911 <dd>
912
913 <p>Unminimizes (UnIconifies) the specified window.</p>
914
915 <p>zero is returned on failure, non-zero for success.</p>
916
917 </dd>
918 </dl>
919
920 <dl>
921
922 <dt id="RaiseWindow-WINDOWID">RaiseWindow WINDOWID</dt>
923 <dd>
924
925 <p>Raises the specified window to the top of the stack, so that no other windows cover it.</p>
926
927 <p>zero is returned on failure, non-zero for success.</p>
928
929 </dd>
930 </dl>
931
932 <dl>
933
934 <dt id="LowerWindow-WINDOWID">LowerWindow WINDOWID</dt>
935 <dd>
936
937 <p>Lowers the specified window to the bottom of the stack, so other existing windows will cover it.</p>
938
939 <p>zero is returned on failure, non-zero for success.</p>
940
941 </dd>
942 </dl>
943
944 <dl>
945
946 <dt id="GetInputFocus">GetInputFocus</dt>
947 <dd>
948
949 <p>Returns the window that currently has the input focus.</p>
950
951 </dd>
952 </dl>
953
954 <dl>
955
956 <dt id="SetInputFocus-WINDOWID">SetInputFocus WINDOWID</dt>
957 <dd>
958
959 <p>Sets the specified window to be the one that has the input focus.</p>
960
961 <p>zero is returned on failure, non-zero for success.</p>
962
963 </dd>
964 </dl>
965
966 <dl>
967
968 <dt id="GetWindowPos-WINDOWID">GetWindowPos WINDOWID</dt>
969 <dd>
970
971 <p>Returns an array containing the position information for the specified window. It also returns size information (including border width) and the number of the screen where the window resides.</p>
972
973 <pre><code>my ($x, $y, $width, $height, $borderWidth, $screen) =
974 GetWindowPos(GetRootWindow());</code></pre>
975
976 </dd>
977 </dl>
978
979 <dl>
980
981 <dt id="GetParentWindow-WINDOWID">GetParentWindow WINDOWID</dt>
982 <dd>
983
984 <p>Returns the parent of the specified window.</p>
985
986 <p>zero is returned if parent couldn&#39;t be determined (i.e., root window).</p>
987
988 </dd>
989 </dl>
990
991 <dl>
992
993 <dt id="GetScreenDepth-SCREEN">GetScreenDepth [SCREEN]</dt>
994 <dd>
995
996 <p>Returns the color depth for the screen. If no screen is specified, it is taken from the value given when opening the X display. If the screen (number) is invalid, -1 will be returned.</p>
997
998 <p>Value is represented as bits, i.e. 16.</p>
999
1000 <pre><code>my $depth = GetScreenDepth();</code></pre>
1001
1002 </dd>
1003 </dl>
1004
1005 <dl>
1006
1007 <dt id="GetScreenRes-SCREEN">GetScreenRes [SCREEN]</dt>
1008 <dd>
1009
1010 <p>Returns the screen resolution. If no screen is specified, it is taken from the value given when opening the X display. If the screen (number) is invalid, the returned list will be empty.</p>
1011
1012 <pre><code>my ($x, $y) = GetScreenRes();</code></pre>
1013
1014 </dd>
1015 </dl>
1016
1017 <h1 id="OTHER-DOCUMENTATION">OTHER DOCUMENTATION</h1>
1018
1019 <p>
1020 <a href='../Changes'>Module Changes</a><br>
1021 <a href='CodingStyle'>Coding-Style Guidelines</a><br>
1022 <a href='../ToDo'>ToDo List</a><br>
1023 <a href='Copying'>Copy of the GPL License</a><br>
1024 </p>
1025
1026 <h1 id="COPYRIGHT">COPYRIGHT</h1>
1027
1028 <p>Copyright(c) 2003-2026 Dennis K. Paulsen, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License.</p>
1029
1030 <h1 id="AUTHOR">AUTHOR</h1>
1031
1032 <p>Dennis K. Paulsen &lt;[email protected]&gt; (Iowa USA)</p>
1033
1034 <h1 id="CONTRIBUTORS">CONTRIBUTORS</h1>
1035
1036 <p>Paulo E. Castro &lt;pauloedgarcastro tata gmail.com&gt;</p>
1037
1038 <h1 id="CREDITS">CREDITS</h1>
1039
1040 <p>Thanks to everyone; including those specifically mentioned below for patches, suggestions, etc.:</p>
1041
1042 <pre><code>David Dick
1043 Alexey Tourbin
1044 Richard Clamp
1045 Gustav Larsson
1046 Nelson D. Caro</code></pre>
1047
1048
1049 </body>
1050
1051 </html>
1052
1053