Add basic XTest functionality, clean up and refactor other sources

This commit is contained in:
Bradlee Speice 2012-06-26 14:07:03 -04:00
parent 62431b5a18
commit ca39bd90be
10 changed files with 699 additions and 44 deletions

View File

@ -6,7 +6,6 @@ AC_INIT(libcvautomation, 0.1, bspeice@uncc.edu)
AM_INIT_AUTOMAKE
#AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SUBDIRS([libcvautomation/] [examples/])
#path intelc110 /opt/coe/intelc110
# Checks for programs.

View File

@ -1,11 +1,12 @@
#Need to include the -Ilibcvautomation so that libcvautomation.h can find everything that it needs
AM_CFLAGS = -Wall -O2 -I$(top_srcdir)/include #-I$(top_srcdir)/include/libcvautomation
if USEOPENCV2
AM_LDFLAGS = -L../libcvautomation/.libs -lcvautomation `pkg-config --libs x11` -lopencv_imgproc -lopencv_core -lopencv_highgui
AM_LDFLAGS = -L../libcvautomation/.libs -lcvautomation `pkg-config --libs x11` -lopencv_imgproc -lopencv_core -lopencv_highgui -lXtst
else
AM_LDFLAGS = -L../libcvautomation/.libs -lcvautomation `pkg-config --libs x11` `pkg-config --libs opencv`
AM_LDFLAGS = -L../libcvautomation/.libs -lcvautomation `pkg-config --libs x11` `pkg-config --libs opencv` -lXtst
endif
#Build only if we're building the examples
bin_PROGRAMS = cva-match
bin_PROGRAMS = cva-match cva-input
cva_match_SOURCES = cva-match.c
cva_input_SOURCES = cva-input.c

102
examples/cva-input.c Normal file
View File

@ -0,0 +1,102 @@
/*
* =====================================================================================
*
* Filename: cva-input.c
*
* Description: This is an example program to demonstrate the XTest and XInput
* functionality in libcvautomation
*
* Version: 1.0
* Created: 06/26/2012 09:20:20 AM
* Revision: none
* Compiler: gcc
*
* Author: Bradlee Speice (), bspeice.nc@gmail.com
* Organization:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
void usage ();
int main( int argc, char** argv )
{
/* Start getopt */
while (1)
{
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
{"usage", no_argument, 0, 'u'},
/* Other valid values are "optional_argument"
* and "required_argument" */
{0, 0, 0, 0}
};
int option_index = 0;
opterr = 0;
int c = getopt_long (argc, argv, "hu", /* Use a single colon for required_argument,
* double colon for optional_argument */
long_options, &option_index);
/* We're done with parsing options */
if (c == -1)
break;
switch (c)
{
case 0:
break;
case 'h':
usage();
break;
case 'u':
usage();
break;
case '?':
/* Error routine */
break;
default:
fprintf( stderr, "Unknown option..." );
exit(0);
};
}
return 0;
}
/*
* === FUNCTION ======================================================================
* Name: usage
* Description: I really shouldn't need to write this
* =====================================================================================
*/
void usage ( )
{
fprintf( stderr, "\n\
<program_name> version <program_version>\n\
\n\
Put your usage or help text here.\n\
\n\
Usage: \n\
\n\
\t-h, --help:\t\tDisplay this usage message.\n\
\t-u, --usage:\t\tDisplay this usage message.\n\
\n\
If you have any questions, comments, concerns, email somebody else.\n" );
exit (0);
} /* ----- end of function usage ----- */

View File

@ -45,10 +45,13 @@ int main( int argc, char** argv )
int search_method = CV_TM_SQDIFF;
int useX = 0; /* bool useX = false; */
int useCenter = 0;
char *xDisplay;
char *xDisplayLocation;
Display *display;
/* This line to suppress a compiler warning */
display = NULL;
/* Set the default display */
xDisplay = "";
xDisplayLocation = "";
/* Set up the linked list for slave images */
basic_list *list_head = NULL, *list_curr = NULL, *list_prev = NULL;
@ -124,10 +127,12 @@ int main( int argc, char** argv )
case 'x':
if ( optarg != NULL ) {
useX = 1;
xDisplay = optarg;
xDisplayLocation = optarg;
display = XOpenDisplay(xDisplayLocation);
} else {
useX = 1;
xDisplay = "";
xDisplayLocation = "";
display = XOpenDisplay(xDisplayLocation);
}
break;
@ -163,9 +168,9 @@ int main( int argc, char** argv )
sub_location = list_curr->fileName;
if (useX && useCenter)
result_point = matchSubImage_X11_location_center( xDisplay, sub_location, search_method, tolerance );
result_point = matchSubImage_X11_location_center( display, sub_location, search_method, tolerance );
else if (useX && !useCenter)
result_point = matchSubImage_X11_location( xDisplay, sub_location, search_method, tolerance );
result_point = matchSubImage_X11_location( display, sub_location, search_method, tolerance );
else if (!useX && useCenter)
result_point = matchSubImage_location_center( root_location, sub_location, search_method, tolerance );
else /* if (!useX && !useCenter) */
@ -188,6 +193,10 @@ int main( int argc, char** argv )
/* And free the final element */
free(list_curr);
/* Clean up X */
if (useX)
XCloseDisplay(display);
return 0;
}

View File

@ -1,7 +1,7 @@
/*
* =====================================================================================
*
* Filename: libcvautomation-x11.h
* Filename: libcvautomation-xlib.h
*
* Description: Function definitions for X11 operations
*
@ -16,8 +16,8 @@
* =====================================================================================
*/
#ifndef LIBCVAUTOMATION_X11_H
#define LIBCVAUTOMATION_X11_H
#ifndef LIBCVAUTOMATION_XLIB_H
#define LIBCVAUTOMATION_XLIB_H
#include <libcvautomation/libcvautomation.h>
@ -30,16 +30,22 @@
* CV_TM_CCOEFF_NORMED
*/
/* Custom wrapper for XOpenDisplay function */
Display* cvaOpenDisplay ( char *displayName );
/* Custom wrapper for XCloseDisplay funtion */
void cvaCloseDisplay ( Display *displayLocation );
/* Match a sub image using the X11 root window as root */
CvPoint matchSubImage_X11( char *displayLocation, IplImage *subImage, int searchMethod, int tolerance );
CvPoint matchSubImage_X11( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance );
/* Match a sub image using the X11 root window as root, return the center */
CvPoint matchSubImage_X11_center( char *displayLocation, IplImage *subImage, int searchMethod, int tolerance );
CvPoint matchSubImage_X11_center( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance );
/* Match a sub image using X11 as root, from filename */
CvPoint matchSubImage_X11_location( char *displayLocation, const char *subImage_location, int search_method, int tolerance );
CvPoint matchSubImage_X11_location( Display *displayLocation, const char *subImage_location, int search_method, int tolerance );
/* Match a sub image using X11 as root, from filename, return the center */
CvPoint matchSubImage_X11_location_center( char *displayLocation, const char *subImage_location, int search_method, int tolerance );
CvPoint matchSubImage_X11_location_center( Display *displayLocation, const char *subImage_location, int search_method, int tolerance );
#endif /* LIBCVAUTOMATION_X11_H */
#endif /* LIBCVAUTOMATION_XLIB_H */

View File

@ -0,0 +1,97 @@
/*
* =====================================================================================
*
* Filename: libcvautomation-xinput.h
*
* Description:
*
* Version: 1.0
* Created: 06/26/2012 09:08:41 AM
* Revision: none
* Compiler: gcc
*
* Author: Bradlee Speice (), bspeice.nc@gmail.com
* Organization:
*
* =====================================================================================
*/
#ifndef LIBCVAUTOMATION_XTEST_H
#define LIBCVAUTOMATION_XTEST_H
#include <libcvautomation/libcvautomation.h>
/* Make sure that the XTest extension is supported.
* If it's not, return 0 (false) */
int xte_xTestSupported ( Display *displayLocation );
/* Get the current location of the pointer */
cvaPoint xte_pointerLocation ( Display *displayLocation );
/* Click the mouse where it is currently at */
void xte_clickMouse ( Display *displayLocation, int mouseButton );
/* Click the mouse on an absolute screen location */
void xte_clickMouseXY ( Display *displayLocation, int xLocation, int yLocation, int mouseButton );
/* Click the mouse on a screen location relative to where it currently is */
void xte_clickMouseRXY ( Display *displayLocation, int xIncrement, int yIncrement, int mouseButton );
/* Click the mouse at the top-left corner of an image on the specified display */
void xte_clickMouseImage ( Display *displayLocation, IplImage *subImage, int mouseButton, int searchMethod, int tolerance );
/* Click the mouse at the top-left corner of an image on the specified display
* where the subImage is a file location */
void xte_clickMouseImage_location ( Display *displayLocation, const char *fileName, int mouseButton, int searchMethod, int tolerance );
/* Click the mouse at the center of an image on the specified display */
void xte_clickMouseImage_center ( Display *displayLocation, IplImage *subImage, int mouseButton, int searchMethod, int tolerance );
/* Click the mouse at the center of an image on the specified display
* where the subImage is a file location */
void xte_clickMouseImage_location_center ( Display *displayLocation, const char *fileName, int mouseButton, int searchMethod, int tolerance );
/* Move the mouse to a location and leave it there */
void xte_hoverMouseXY ( Display *displayLocation, int xLocation, int yLocation );
/* Move the mouse to a location relative to where it currently is and leave it there */
void xte_hoverMouseRXY ( Display *displayLocation, int xIncrement, int yIncrement );
/* Move the mouse to a location at the top-left corner of an image on the specified display
* but don't click the mouse */
void xte_hoverMouseImage ( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance );
/* Move the mouse to a location at the top-left corner of an image from file on the specified display
* but don't click the mouse */
void xte_hoverMouseImage_location ( Display *displayLocation, const char *filename, int searchMethod, int tolerance );
/* Move the mouse to a location at the center of an image on the specified display
* but don't click the mouse */
void xte_hoverMouseImage_center ( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance );
/* Move the mouse to a location at the center of an image from file on the specified display
* but don't click the mouse */
void xte_hoverMouseImage_location_center ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance );
/* Push a mouse button down, but don't release it */
void xte_mouseDown ( Display *displayLocation, int mouseButton );
/* Let a mouse button up */
void xte_mouseUp ( Display *displayLocation, int mouseButton );
/* Move the mouse a little bit */
void xte_mouseJiggle ( Display *displayLocation );
/* Press and release a single key */
void xte_clickKey ( Display *displayLocation, char key );
/* Press and release keys in a string */
void xte_clickKeyStr ( Display *displayLocation, const char *string );
/* Press a key down */
void xte_keyDown ( Display *displayLocation, char key );
/* Release a key */
void xte_keyUp ( Display *displayLocation, char key );
#endif /* LIBCVAUTOMATION_XTEST_H */

View File

@ -37,6 +37,7 @@
/* X11 includes */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/XTest.h>
/* Define a basic structure to help us with using multiple-picture arguments
* Yes, it's a hackish implementation, nobody said you had to use this one. */
@ -51,10 +52,16 @@ typedef struct {
} cvautomationList;
/* Define another basic structure for points */
typedef struct {
int x, y;
} cvaPoint;
/* Project component includes */
/* The includes come here to make sure all function prototypes have access
* to the cvautomationList struct */
#include <libcvautomation/libcvautomation-opencv.h>
#include <libcvautomation/libcvautomation-x11.h>
#include <libcvautomation/libcvautomation-xlib.h>
#include <libcvautomation/libcvautomation-xtest.h>
#endif /* LIBCVAUTOMATION_H */

View File

@ -4,8 +4,8 @@ AM_LIBS = -shared
#Lists the libraries to build
lib_LTLIBRARIES = libcvautomation.la
libcvautomation_la_SOURCES = libcvautomation-opencv.c libcvautomation-opencv.h libcvautomation-x11.c libcvautomation-x11.h libcvautomation.h
libcvautomation_la_SOURCES = libcvautomation-opencv.c libcvautomation-opencv.h libcvautomation-xlib.c libcvautomation-xlib.h libcvautomation.h libcvautomation-xtest.c libcvautomation-xtest.h
#libcvautomation_CFLAGS = -shared -I$(top_srcdir)/include -I$(top_srcdir)/libcvautomation -I$(top_srcdir)/include/libcvautomation
#Lists the headers to distribute
pkginclude_HEADERS = $(top_srcdir)/include/libcvautomation/libcvautomation.h $(top_srcdir)/include/libcvautomation/libcvautomation-opencv.h $(top_srcdir)/include/libcvautomation/libcvautomation-x11.h
pkginclude_HEADERS = $(top_srcdir)/include/libcvautomation/libcvautomation.h $(top_srcdir)/include/libcvautomation/libcvautomation-opencv.h $(top_srcdir)/include/libcvautomation/libcvautomation-xlib.h $(top_srcdir)/include/libcvautomation/libcvautomation-xtest.h

View File

@ -1,7 +1,7 @@
/*
* =====================================================================================
*
* Filename: libcvautomation-x11.c
* Filename: libcvautomation-xlib.c
*
* Description:
*
@ -16,7 +16,30 @@
* =====================================================================================
*/
#include <libcvautomation/libcvautomation-x11.h>
#include <libcvautomation/libcvautomation-xlib.h>
/*
* === FUNCTION ======================================================================
* Name: cvaOpenDisplay
* Description: Custom wrapper for XOpenDisplay function
* =====================================================================================
*/
Display* cvaOpenDisplay ( char *displayName )
{
return XOpenDisplay( displayName);
}
/*
* === FUNCTION ======================================================================
* Name: cvaCloseDisplay
* Description: Custom wrapper for XOpenDisplay function
* =====================================================================================
*/
void cvaCloseDisplay ( Display *displayLocation )
{
XCloseDisplay( displayLocation );
}
/*
* === FUNCTION ======================================================================
@ -24,7 +47,7 @@
* Description: Match a sub image using the X11 root window as root
* =====================================================================================
*/
CvPoint matchSubImage_X11( char *displayLocation, IplImage *subImage, int searchMethod, int tolerance )
CvPoint matchSubImage_X11( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance )
{
/* First things first, grab the root X window and convert it to
* the IplImage format.
@ -36,7 +59,6 @@ CvPoint matchSubImage_X11( char *displayLocation, IplImage *subImage, int search
XImage *rootImage;
XColor color;
Display *display;
Screen *screen;
unsigned long rmask, gmask, bmask;
unsigned long rshift, rbits,
@ -48,18 +70,17 @@ CvPoint matchSubImage_X11( char *displayLocation, IplImage *subImage, int search
unsigned int width, height;
/* Setting up the X screengrab is the first order of business */
display = XOpenDisplay(displayLocation);
screen = DefaultScreenOfDisplay(display);
screen = DefaultScreenOfDisplay(displayLocation);
width = screen->width;
height = screen->height;
rootImage = XGetImage( display, DefaultRootWindow(display),
rootImage = XGetImage( displayLocation, DefaultRootWindow(displayLocation),
startX, startY, width, height,
AllPlanes, ZPixmap );
/* Make sure that we're good to go before going any farther */
if ( rootImage == NULL || display == NULL || screen == NULL )
if ( rootImage == NULL || displayLocation == NULL || screen == NULL )
{
fprintf( stderr, "Couldn't grab the root window!" );
resultPoint.x = -1;
@ -144,11 +165,11 @@ CvPoint matchSubImage_X11( char *displayLocation, IplImage *subImage, int search
/* I don't know how this works either. */
/* TODO: Figure out how this code works and document it */
Colormap colormap;
colormap = DefaultColormap( display, DefaultScreen ( display ));
colormap = DefaultColormap( displayLocation, DefaultScreen( displayLocation ));
for ( x = 0; x < rootImage->width; x++ ) {
for ( y = 0; y < rootImage->height; y++ ) {
color.pixel = XGetPixel ( rootImage, x, y );
XQueryColor( display, colormap, &color );
XQueryColor( displayLocation, colormap, &color );
CV_IMAGE_ELEM(X_IPL, uchar, y, x * X_IPL->nChannels) = color.blue;
CV_IMAGE_ELEM(X_IPL, uchar, y, x * X_IPL->nChannels + 1) = color.green;
CV_IMAGE_ELEM(X_IPL, uchar, y, x * X_IPL->nChannels + 2) = color.red;
@ -164,7 +185,6 @@ CvPoint matchSubImage_X11( char *displayLocation, IplImage *subImage, int search
/* Clean up the CV image we created, as well as all X resources */
XDestroyImage( rootImage );
XCloseDisplay( display );
cvReleaseImage( &X_IPL );
/* Return and be done */
@ -178,7 +198,7 @@ CvPoint matchSubImage_X11( char *displayLocation, IplImage *subImage, int search
* Description: Match a sub image using the X11 root window as root, from filename
* =====================================================================================
*/
CvPoint matchSubImage_X11_location( char *displayLocation, const char *subImage_location, int searchMethod, int tolerance )
CvPoint matchSubImage_X11_location( Display *displayLocation, const char *subImage_location, int searchMethod, int tolerance )
{
/* This is basically a wrapper for matchSubImage_X11( char *display, IplImage )
* All we do is load the sub-image from the given filename, and then
@ -218,7 +238,7 @@ CvPoint matchSubImage_X11_location( char *displayLocation, const char *subImage_
* the top-left corner.
* =====================================================================================
*/
CvPoint matchSubImage_X11_center( char *displayLocation, IplImage *subImage, int searchMethod, int tolerance )
CvPoint matchSubImage_X11_center( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance )
{
/* First things first, grab the root X window and convert it to
* the IplImage format.
@ -230,7 +250,6 @@ CvPoint matchSubImage_X11_center( char *displayLocation, IplImage *subImage, int
XImage *rootImage;
XColor color;
Display *display;
Screen *screen;
unsigned long rmask, gmask, bmask;
unsigned long rshift, rbits,
@ -242,18 +261,17 @@ CvPoint matchSubImage_X11_center( char *displayLocation, IplImage *subImage, int
unsigned int width, height;
/* Setting up the X screengrab is the first order of business */
display = XOpenDisplay(displayLocation);
screen = DefaultScreenOfDisplay(display);
screen = DefaultScreenOfDisplay(displayLocation);
width = screen->width;
height = screen->height;
rootImage = XGetImage( display, DefaultRootWindow(display),
rootImage = XGetImage( displayLocation, DefaultRootWindow(displayLocation),
startX, startY, width, height,
AllPlanes, ZPixmap );
/* Make sure that we're good to go before going any farther */
if ( rootImage == NULL || display == NULL || screen == NULL )
if ( rootImage == NULL || displayLocation == NULL || screen == NULL )
{
fprintf( stderr, "Couldn't grab the root window!" );
resultPoint.x = -1;
@ -338,11 +356,11 @@ CvPoint matchSubImage_X11_center( char *displayLocation, IplImage *subImage, int
/* I don't know how this works either. */
/* TODO: Figure out how this code works and document it */
Colormap colormap;
colormap = DefaultColormap( display, DefaultScreen ( display ));
colormap = DefaultColormap( displayLocation, DefaultScreen( displayLocation ));
for ( x = 0; x < rootImage->width; x++ ) {
for ( y = 0; y < rootImage->height; y++ ) {
color.pixel = XGetPixel ( rootImage, x, y );
XQueryColor( display, colormap, &color );
XQueryColor( displayLocation, colormap, &color );
CV_IMAGE_ELEM(X_IPL, uchar, y, x * X_IPL->nChannels) = color.blue;
CV_IMAGE_ELEM(X_IPL, uchar, y, x * X_IPL->nChannels + 1) = color.green;
CV_IMAGE_ELEM(X_IPL, uchar, y, x * X_IPL->nChannels + 2) = color.red;
@ -354,11 +372,10 @@ CvPoint matchSubImage_X11_center( char *displayLocation, IplImage *subImage, int
* However, we don't want to do any more work than we have to - send our images off
* to matchSubImage in libopencvautomation-opencv. */
resultPoint = matchSubImage_center ( X_IPL, subImage, searchMethod, tolerance );
resultPoint = matchSubImage_center( X_IPL, subImage, searchMethod, tolerance );
/* Clean up the CV image we created, as well as all X resources */
XDestroyImage( rootImage );
XCloseDisplay( display );
cvReleaseImage( &X_IPL );
/* Return and be done */
@ -372,7 +389,7 @@ CvPoint matchSubImage_X11_center( char *displayLocation, IplImage *subImage, int
* Description: Match a sub image using the X11 root window as root, from filename
* =====================================================================================
*/
CvPoint matchSubImage_X11_location_center( char *displayLocation, const char *subImage_location, int searchMethod, int tolerance )
CvPoint matchSubImage_X11_location_center( Display *displayLocation, const char *subImage_location, int searchMethod, int tolerance )
{
/* This is basically a wrapper for matchSubImage_X11( char *display, IplImage )
* All we do is load the sub-image from the given filename, and then

View File

@ -0,0 +1,417 @@
/*
* =====================================================================================
*
* Filename: libcvautomation-xinput.c
*
* Description:
*
* Version: 1.0
* Created: 06/26/2012 09:09:05 AM
* Revision: none
* Compiler: gcc
*
* Author: Bradlee Speice (), bspeice.nc@gmail.com
* Organization:
*
* =====================================================================================
*/
#include <libcvautomation/libcvautomation-xtest.h>
/*
* === FUNCTION ======================================================================
* Name: xte_xTestSupported
* Description: Make sure that the XTest extension is supported.
* If it's not, return 0 (false)
* =====================================================================================
*/
int xte_XTestSupported ( Display *displayLocation )
{
int event_basep, error_basep, majorp, minorp;
return XTestQueryExtension( displayLocation, &event_basep, &error_basep, &majorp, &minorp );
}
/*
* === FUNCTION ======================================================================
* Name: xte_pointerLocation
* Description: Return the current location of the pointer
* =====================================================================================
*/
cvaPoint xte_pointerLocation ( Display *displayLocation )
{
/* The next few variables we discard, but need them for the function call */
Window root, child;
int rootX, rootY;
unsigned int mask_return;
/* End the discarded variables. We're using the ones that follow */
int pointerX, pointerY;
XQueryPointer( displayLocation, DefaultRootWindow( displayLocation ),
&root, &child, &rootX, &rootY,
/* And then the stuff we actually care about */
&pointerX, &pointerY,
/* And more stuff we don't */
&mask_return );
cvaPoint returnPoint;
returnPoint.x = pointerX;
returnPoint.y = pointerY;
return returnPoint;
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickMouse
* Description: Click the mouse where it is currently at
* =====================================================================================
*/
void xte_clickMouse ( Display *displayLocation, int mouseButton )
{
XTestFakeButtonEvent( displayLocation, mouseButton, 1, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 0, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickMouseXY
* Description: Click the mouse on a screen location
* =====================================================================================
*/
void xte_clickMouseXY ( Display *displayLocation, int xLocation, int yLocation, int mouseButton )
{
/* To avoid specifying the screen number we're using, calculate the pointer's
* current location, and move to the new wanted location using relative motion */
cvaPoint pointerLocation = xte_pointerLocation( displayLocation );
int xIncrement, yIncrement;
xIncrement = xLocation - pointerLocation.x;
yIncrement = yLocation - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, xIncrement, yIncrement, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 1, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 0, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickMouseRXY
* Description: Click the mouse on a screen location relative to where it currently is
* =====================================================================================
*/
void xte_clickMouseRXY ( Display *displayLocation, int xIncrement, int yIncrement, int mouseButton )
{
XTestFakeRelativeMotionEvent( displayLocation, xIncrement, yIncrement, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 1, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 0, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickMouseImage
* Description: Click the mouse at the top-left corner of an image on the specified display
* =====================================================================================
*/
void xte_clickMouseImage ( Display *displayLocation, IplImage *subImage, int mouseButton, int searchMethod, int tolerance )
{
/* This one is a bit more in-depth -
* Find where the image is at
* Find where the cursor is currently at
* Move the cursor to the given point using relative motion -
* This method is screen-agnostic */
CvPoint resultPoint;
resultPoint = matchSubImage_X11 ( displayLocation, subImage, searchMethod, tolerance );
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int movementX, movementY;
movementX = resultPoint.x - pointerLocation.x;
movementY = resultPoint.y - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, movementX, movementY, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 1, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 0, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickMouseImage_location
* Description: Click the mouse at the top-left corner of an image on the specified display
* where the subImage is a file location
* =====================================================================================
*/
void xte_clickMouseImage_location ( Display *displayLocation, const char *fileName, int mouseButton, int searchMethod, int tolerance )
{
CvPoint resultPoint;
resultPoint = matchSubImage_X11_location( displayLocation, fileName, searchMethod, tolerance );
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int movementX, movementY;
movementX = resultPoint.x - pointerLocation.x;
movementY = resultPoint.y - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, movementX, movementY, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 1, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 0, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickMouseImage_center
* Description: Click the mouse at the center of an image on the specified display
* =====================================================================================
*/
void xte_clickMouseImage_center ( Display *displayLocation, IplImage *subImage, int mouseButton, int searchMethod, int tolerance )
{
/* This one is a bit more in-depth -
* Find where the image is at
* Find where the cursor is currently at
* Move the cursor to the given point using relative motion -
* This method is screen-agnostic */
CvPoint resultPoint;
resultPoint = matchSubImage_X11_center ( displayLocation, subImage, searchMethod, tolerance );
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int movementX, movementY;
movementX = resultPoint.x - pointerLocation.x;
movementY = resultPoint.y - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, movementX, movementY, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 1, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 0, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickMouseImage_location_center
* Description: Click the mouse at the center of an image on the specified display
* where the subImage is a file location
* =====================================================================================
*/
void xte_clickMouseImage_location_center ( Display *displayLocation, const char *fileName, int mouseButton, int searchMethod, int tolerance )
{
CvPoint resultPoint;
resultPoint = matchSubImage_X11_location_center( displayLocation, fileName, searchMethod, tolerance );
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int movementX, movementY;
movementX = resultPoint.x - pointerLocation.x;
movementY = resultPoint.y - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, movementX, movementY, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 1, CurrentTime );
XTestFakeButtonEvent( displayLocation, mouseButton, 0, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_hoverMouseXY
* Description: Move the mouse to a location and leave it there
* =====================================================================================
*/
void xte_hoverMouseXY ( Display *displayLocation, int xLocation, int yLocation )
{
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int xIncrement, yIncrement;
xIncrement = xLocation - pointerLocation.x;
yIncrement = yLocation - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, xIncrement, yIncrement, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_hoverMouseRXY
* Description: Move the mouse to a location relative to where it currently is
* and leave it there
* =====================================================================================
*/
void xte_hoverMouseRXY ( Display *displayLocation, int xIncrement, int yIncrement )
{
XTestFakeRelativeMotionEvent( displayLocation, xIncrement, yIncrement, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_hoverMouseMouseImage
* Description: Move the mouse to a location at the top-left corner of an image on
* the specified display but don't click the mouse
* =====================================================================================
*/
void xte_hoverMouseImage ( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance )
{
CvPoint resultPoint;
resultPoint = matchSubImage_X11( displayLocation, subImage, searchMethod, tolerance );
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int xIncrement, yIncrement;
xIncrement = resultPoint.x - pointerLocation.x;
yIncrement = resultPoint.y - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, xIncrement, yIncrement, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_hoverMouseMouseImage_location
* Description: Move the mouse to a location at the top-left corner of an image from
* file on the specified display but don't click the mouse
* =====================================================================================
*/
void xte_hoverMouseImage_location ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance )
{
CvPoint resultPoint;
resultPoint = matchSubImage_X11_location( displayLocation, fileName, searchMethod, tolerance );
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int xIncrement, yIncrement;
xIncrement = resultPoint.x - pointerLocation.x;
yIncrement = resultPoint.y - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, xIncrement, yIncrement, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_hoverMouseMouseImage_center
* Description: Move the mouse to a location at the center of an image on the
* specified display but don't click the mouse
* =====================================================================================
*/
void xte_hoverMouseImage_center ( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance )
{
CvPoint resultPoint;
resultPoint = matchSubImage_X11_center( displayLocation, subImage, searchMethod, tolerance );
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int xIncrement, yIncrement;
xIncrement = resultPoint.x - pointerLocation.x;
yIncrement = resultPoint.y - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, xIncrement, yIncrement, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_hoverMouseMouseImage_location_center
* Description: Move the mouse to a location at the center of an image from file on
* the specified display but don't click the mouse
* =====================================================================================
*/
void xte_hoverMouseImage_location_center ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance )
{
CvPoint resultPoint;
resultPoint = matchSubImage_X11_location_center( displayLocation, fileName, searchMethod, tolerance );
cvaPoint pointerLocation;
pointerLocation = xte_pointerLocation( displayLocation );
int xIncrement, yIncrement;
xIncrement = resultPoint.x - pointerLocation.x;
yIncrement = resultPoint.y - pointerLocation.y;
XTestFakeRelativeMotionEvent( displayLocation, xIncrement, yIncrement, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_mouseDown
* Description: Push a mouse button down, but don't release it
* =====================================================================================
*/
void xte_mouseDown ( Display *displayLocation, int mouseButton )
{
XTestFakeButtonEvent( displayLocation, mouseButton, 1, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_mouseUp
* Description: Let a mouse button up
* =====================================================================================
*/
void xte_mouseUp ( Display *displayLocation, int mouseButton )
{
XTestFakeButtonEvent( displayLocation, mouseButton, 0, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_mouseJiggle
* Description: Move the mouse a little bit
* =====================================================================================
*/
void xte_mouseJiggle ( Display *displayLocation )
{
XTestFakeRelativeMotionEvent( displayLocation, 1, 1, CurrentTime );
XTestFakeRelativeMotionEvent( displayLocation, -1, -1, CurrentTime );
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickKey
* Description: Press and release a single key
* =====================================================================================
*/
void xte_clickKey ( Display *displayLocation, char key )
{
}
/*
* === FUNCTION ======================================================================
* Name: xte_clickKeyStr
* Description: Press and release keys in a string
* =====================================================================================
*/
void xte_clickKeyStr ( Display *displayLocation, const char *string )
{
}
/*
* === FUNCTION ======================================================================
* Name: xte_keyDown
* Description: Press a key down
* =====================================================================================
*/
void xte_keyDown ( Display *displayLocation, char key )
{
}
/*
* === FUNCTION ======================================================================
* Name: xte_keyUp
* Description: Release a key
* =====================================================================================
*/
void xte_keyUp ( Display *displayLocation, char key )
{
}