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