LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-09-2008, 03:54 PM   #1
juanctes
Member
 
Registered: Dec 2004
Location: Argentina, corrientes (far from buenos aires, to the north)
Distribution: Ubuntu :(
Posts: 74

Rep: Reputation: 15
JAVA! generate mouse events


Hi, hope to be clear enough so someone can help me.
After a couple of hours digging i cant find a way to make a java program to generate mouse events. I found the Robot class that has the method mousemove(x,y) but I dont need the pointer to be relocated at some position in the screen.
What i need is to translate some input (from jinput, already reading a book on that) to "real" mouse movements.
for example:
if you press key 1: the mouse should go 1 unit forward.
if you press key 2: the mouse should go 2 units forward.
and so on..

the Robot.mousemove(x,y) will magically make the pointer appear at x y in the screen. besides if I see that the pointer is at (10, 10) an I relocate it at (10,9) and repeat it several times the screen will end at (10,0)...

I would like to enable an other program that is expecting mouse movements to believe that the mouse moved forward, backward, etc... like if someone actually moved the mouse. NOTHING TO DO WITH the screen!

Hope someone knows how to do this.
cheers!
 
Old 12-10-2008, 10:33 AM   #2
elprawn
Member
 
Registered: Feb 2005
Distribution: Gentoo 2008
Posts: 138

Rep: Reputation: 15
So basically, you're trying to move the cursor programatically?
 
Old 12-10-2008, 01:06 PM   #3
juanctes
Member
 
Registered: Dec 2004
Location: Argentina, corrientes (far from buenos aires, to the north)
Distribution: Ubuntu :(
Posts: 74

Original Poster
Rep: Reputation: 15
hi, a new lesson i learned today:
Quote:
Be Forthright When Cross Posting To Other Sites.
It can be frustrating posting an elaborate answer only to later find out that someone has posted the same answer previously on another forum.
I asked the same questionat those sites in order to maximize the chances of getting a good answer:
http://saloon.javaranch.com/cgi-bin/...2&t=018380&p=1
http://forums.sun.com/thread.jspa?threadID=5354012
-------------
so, basically I need to make the same effect as if the user is moving the mouse, not just relocating the pointer at some coordinates. Imagine a program that would be rolling a ball if the user is moving the mouse, here the screen coordinates doesn't help..
 
Old 12-10-2008, 01:10 PM   #4
juanctes
Member
 
Registered: Dec 2004
Location: Argentina, corrientes (far from buenos aires, to the north)
Distribution: Ubuntu :(
Posts: 74

Original Poster
Rep: Reputation: 15
here is the answer! didn't test it yet but if someone needs it before I can post some example here it is..
THANKS to guys in Javaranch.
Quote:
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
new MouseEvent( miComponente,MouseEvent.MOUSE_CLICKED,0,0,-1,-1,2,false ) );
in this link you'll find more. if you like spanish... other wise googling '"new MouseEvent"' would do.
http://www.itapizaco.edu.mx/paginas/.../cap11-13.html
C yah!

Last edited by juanctes; 12-10-2008 at 01:12 PM.
 
  


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
Keyboard events interrupting mouse events. miner49er Linux - Hardware 3 11-04-2008 04:16 AM
Mouse interrupting keyboard events, can't type while mouse is moving sandaili Linux - Hardware 0 08-04-2008 06:56 PM
Java: Generate html code Clemente Programming 6 11-26-2006 01:39 PM
how to generate a mouse click events from a kernel module yugandhar Linux - Kernel 1 09-13-2006 07:58 AM
Java action events AMMullan Programming 22 04-16-2004 04:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:28 PM.

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