mirror of
https://github.com/bspeice/libcvautomation
synced 2025-07-01 13:56:49 -04:00
Flesh out the cva-input program, and add calls to XFlush()
This commit is contained in:
@ -18,15 +18,41 @@
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <libcvautomation/libcvautomation.h>
|
||||
|
||||
void usage ();
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/* Set up for getopt */
|
||||
int mouseXMovement, mouseYMovement;
|
||||
/* Safe to say that nobody will ever need to move INT_MAX
|
||||
* pixels. INT_MAX is used to signify an uninitialized value. */
|
||||
mouseXMovement = mouseYMovement = INT_MAX;
|
||||
cvaPoint currentLocation;
|
||||
char *mouseImage;
|
||||
mouseImage = NULL;
|
||||
Bool useMouseImage;
|
||||
useMouseImage = False;
|
||||
int mouseButton;
|
||||
mouseButton = 1;
|
||||
char *keypress;
|
||||
keypress = NULL;
|
||||
char *xDisplayLocation;
|
||||
xDisplayLocation = "";
|
||||
Display *display;
|
||||
display = NULL;
|
||||
Bool useCenter;
|
||||
useCenter = False;
|
||||
|
||||
int searchMethod, tolerance;
|
||||
searchMethod = 0;
|
||||
tolerance = INT_MAX;
|
||||
|
||||
/* Start getopt */
|
||||
while (1)
|
||||
{
|
||||
@ -34,6 +60,17 @@ int main( int argc, char** argv )
|
||||
{
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"usage", no_argument, 0, 'u'},
|
||||
{"display", required_argument, 0, 'd'},
|
||||
{"move-mousex", required_argument, 0, 'x'},
|
||||
{"move-mousey", required_argument, 0, 'y'},
|
||||
{"mover-mousex",required_argument, 0, 'r'},
|
||||
{"mover-mousey",required_argument, 0, 's'},
|
||||
{"movei-mouse", required_argument, 0, 'i'},
|
||||
{"keypress", required_argument, 0, 'k'},
|
||||
{"search-method",required_argument, 0, 'm'},
|
||||
{"tolerance", required_argument, 0, 't'},
|
||||
{"button", required_argument, 0, 'b'},
|
||||
{"center", no_argument, 0, 'c'},
|
||||
/* Other valid values are "optional_argument"
|
||||
* and "required_argument" */
|
||||
{0, 0, 0, 0}
|
||||
@ -42,7 +79,7 @@ int main( int argc, char** argv )
|
||||
int option_index = 0;
|
||||
opterr = 0;
|
||||
|
||||
int c = getopt_long (argc, argv, "hu", /* Use a single colon for required_argument,
|
||||
int c = getopt_long (argc, argv, "hux:y:r:s:i:k:", /* Use a single colon for required_argument,
|
||||
* double colon for optional_argument */
|
||||
long_options, &option_index);
|
||||
|
||||
@ -63,6 +100,60 @@ int main( int argc, char** argv )
|
||||
usage();
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
xDisplayLocation = optarg;
|
||||
|
||||
case 'x':
|
||||
if ( display == NULL )
|
||||
display = XOpenDisplay( xDisplayLocation );
|
||||
currentLocation = xte_pointerLocation( display );
|
||||
|
||||
mouseXMovement = atoi(optarg) - currentLocation.x;
|
||||
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
if ( display == NULL )
|
||||
display = XOpenDisplay( xDisplayLocation );
|
||||
currentLocation = xte_pointerLocation( display );
|
||||
|
||||
mouseYMovement = atoi(optarg) - currentLocation.y;
|
||||
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
mouseXMovement = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
mouseYMovement = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
useMouseImage = True;
|
||||
mouseImage = optarg;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
keypress = optarg;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
searchMethod = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
tolerance = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
mouseButton = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
useCenter = True;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
/* Error routine */
|
||||
break;
|
||||
@ -73,6 +164,41 @@ int main( int argc, char** argv )
|
||||
};
|
||||
}
|
||||
|
||||
/* If we haven't opened our display yet, do that now.
|
||||
* Note that we will only ever open one display due to
|
||||
* checks implemented in the optarg section. */
|
||||
if (display == NULL)
|
||||
display = XOpenDisplay( xDisplayLocation );
|
||||
|
||||
if (! xte_XTestSupported( display ))
|
||||
{
|
||||
printf("The XTest extension is not supported! Aborting...");
|
||||
exit(255);
|
||||
}
|
||||
|
||||
if (useMouseImage)
|
||||
{
|
||||
if (useCenter)
|
||||
xte_clickMouseImage_location( display, mouseImage, mouseButton, searchMethod, tolerance );
|
||||
else
|
||||
xte_clickMouseImage_location_center( display, mouseImage, mouseButton, searchMethod, tolerance );
|
||||
}
|
||||
|
||||
else if (keypress != NULL)
|
||||
xte_clickKey( display, keypress );
|
||||
|
||||
else
|
||||
{
|
||||
if (mouseXMovement == INT_MAX)
|
||||
mouseXMovement = 0;
|
||||
if (mouseYMovement == INT_MAX)
|
||||
mouseYMovement = 0;
|
||||
|
||||
printf("%i, %i\n", mouseXMovement, mouseYMovement);
|
||||
xte_clickMouseRXY( display, mouseXMovement, mouseYMovement, mouseButton );
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -85,16 +211,33 @@ int main( int argc, char** argv )
|
||||
void usage ( )
|
||||
{
|
||||
fprintf( stderr, "\n\
|
||||
<program_name> version <program_version>\n\
|
||||
cva-input -i <image_file>\n\
|
||||
cva-input -x <x_location> -y <y_location>\n\
|
||||
cva-input -k <key>\n\
|
||||
\n\
|
||||
Put your usage or help text here.\n\
|
||||
The cva-input program demonstrates the XTest section of libcvautomation.\n\
|
||||
\n\
|
||||
Usage: \n\
|
||||
\n\
|
||||
\t-h, --help:\t\tDisplay this usage message.\n\
|
||||
\t-u, --usage:\t\tDisplay this usage message.\n\
|
||||
\t-d, --display:\t\tSpecify the X display to use.\n\
|
||||
\t-x, --move-mousex:\tSpecify the end location of the mouse (x-coordinate).\n\
|
||||
\t-y, --move-mousey:\tSpecify the end location of the mouse (y-coordinate).\n\
|
||||
\t-r, --mover-mousex:\tSpecify the distance in the X plane to move the mouse.\n\
|
||||
\t-s, --mover-mousey:\tSpecify the distance in the Y plane to move the mouse.\n\
|
||||
\t-i, --movei-mouse:\tSpecify an image to click.\n\
|
||||
\t\t\t\tBy default, the program will click the top-left corner of the image.\n\
|
||||
\t\t\t\tUse the \"-c\" switch to change this.\n\
|
||||
\t-k, --keypress:\t\tSpecify a key to press.\n\
|
||||
\t-m, --search-method:\tSpecify a method to search by. See \`cva-match --help\'\n\
|
||||
\t\t\t\tfor more information on this.\n\
|
||||
\t-t, --tolerance:\tSpecify how strict the match is.\n\
|
||||
\t-b, --button:\t\tSpecify the mouse button to press (default 1).\n\
|
||||
\t-c, --center:\t\tInstead of matching the top-left corner of an image,\n\
|
||||
\t\t\t\tmatch the center of the image.\n\
|
||||
\n\
|
||||
If you have any questions, comments, concerns, email somebody else.\n" );
|
||||
If you have any questions, comments, concerns, email <bspeice@uncc.edu>.\n\n" );
|
||||
|
||||
exit (0);
|
||||
|
||||
|
Reference in New Issue
Block a user