LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-14-2009, 05:10 AM   #1
jovie
Member
 
Registered: May 2006
Posts: 54

Rep: Reputation: 15
xdotool, XSendEvent or something like them


Hi

I've got a java program that takes many hrs to analyse data then requires user intervention (a mouse click) to start building the directional graphs, (which take 1hr+).

I wrote a shell script using xdotool to automate the user input but it won't work when the screen is locked, it clicks on the screen saver not the target window.

I thought XSendEvent might work but it seems to be a C++ function and I don't know that language.

Does anyone know of another way round my problem?

Many thanks


[root]# cat /proc/version
Linux version 2.6.27.24-170.2.68.fc10.i686 (mockbuild@x86-4.fedora.phx.redhat.com) (gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC) ) #1 SMP Wed May 20 23:10:16 EDT 2009
 
Old 01-09-2012, 10:06 AM   #2
aman_madaan
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
Code:
//sg
#include <X11/Xlib.h>
#include<stdio.h>
#include<unistd.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>

void mouseClick(int button)
{
	Display *display = XOpenDisplay(NULL);

	XEvent event;
	
	if(display == NULL)
	{
		fprintf(stderr, "Errore nell'apertura del Display !!!\n");
		exit(EXIT_FAILURE);
	}
	
	memset(&event, 0x00, sizeof(event));
	
	event.type = ButtonPress;
	event.xbutton.button = button;
	event.xbutton.same_screen = True;
	
	XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
	
	event.xbutton.subwindow = event.xbutton.window;
	
	while(event.xbutton.subwindow)
	{
		event.xbutton.window = event.xbutton.subwindow;
		
		XQueryPointer(display, event.xbutton.window, &event.xbutton.root, &event.xbutton.subwindow, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
	}
	
	if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Error\n");
	
	XFlush(display);
	
	usleep(100000);
	
	event.type = ButtonRelease;
	event.xbutton.state = 0x100;
	
	if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Error\n");
	
	XFlush(display);
	
	XCloseDisplay(display);
}
int main(int argc,char * argv[]) {
int i=0;
    int x , y;
x=atoi(argv[1]);
y=atoi(argv[2]);
    Display *display = XOpenDisplay(0);
Window root = DefaultRootWindow(display);

    XWarpPointer(display, None, root, 0, 0, 0, 0, x, y);


mouseClick(Button1);
XFlush(display);

    XCloseDisplay(display);
    return 0;
}

build this program.suppose the out file is called a.out
then the java code can be written as :

Process proc = rt.exec("./a.out "+x+" "+y);
int exitVal = proc.waitFor();
System.out.println("Process exitvalue: " + exitVal);
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to send with xdotool a window to another Desktop X number? frenchn00b Linux - General 1 10-23-2009 12:31 PM
Xlib / XSendEvent and kuickshow, kate demerson3 Programming 0 05-14-2006 06:11 AM
XLib problem (XSendEvent) muratungor Programming 0 07-26-2005 07:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration