Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Mouse position relative to screen (http://www.velocityreviews.com/forums/t136129-mouse-position-relative-to-screen.html)

MAB 08-17-2004 11:57 AM

Mouse position relative to screen
 
How do I get the position of the mouse relative to the top left of the
screen. The MouseMotionListener works relative to some component of the app
but what if I have no visual component and I want the absolute position of
the mouse?

thx



VisionSet 08-17-2004 01:19 PM

Re: Mouse position relative to screen
 
"MAB" <bad-email@nowhere.com> wrote in message
news:2oea0vF9n67bU1@uni-berlin.de...
> How do I get the position of the mouse relative to the top left of the
> screen. The MouseMotionListener works relative to some component of the

app
> but what if I have no visual component and I want the absolute position of
> the mouse?
>


SwingUtilities.convertPointToScreen(Point p, Component c)

--
Mike W



VisionSet 08-17-2004 01:20 PM

Re: Mouse position relative to screen
 

"VisionSet" <spam@ntlworld.com> wrote in message
news:SBnUc.1429$%%5.1040@newsfe5-gui.ntli.net...
> "MAB" <bad-email@nowhere.com> wrote in message
> news:2oea0vF9n67bU1@uni-berlin.de...
> > How do I get the position of the mouse relative to the top left of the
> > screen. The MouseMotionListener works relative to some component of the

> app
> > but what if I have no visual component and I want the absolute position

of
> > the mouse?
> >

>
> SwingUtilities.convertPointToScreen(Point p, Component c)
>


Ooops, sorry must read more carefully!

--
Mike W



Matt Humphrey 08-17-2004 01:54 PM

Re: Mouse position relative to screen
 

"MAB" <bad-email@nowhere.com> wrote in message
news:2oea0vF9n67bU1@uni-berlin.de...
> How do I get the position of the mouse relative to the top left of the
> screen. The MouseMotionListener works relative to some component of the

app
> but what if I have no visual component and I want the absolute position of
> the mouse?


How are you getting mouse events if they're not in the context of some
Component? Are you really asking how to poll the position of the cursor on
the screen? Check out the full-screen mode--that will give you a Graphics
Context that covers the entire screen.

Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/



Paul Lutus 08-17-2004 02:07 PM

Re: Mouse position relative to screen
 
MAB wrote:

> How do I get the position of the mouse relative to the top left of the
> screen. The MouseMotionListener works relative to some component of the
> app but what if I have no visual component and I want the absolute
> position of the mouse?


Basically, what the other posters are telling you is, to get the mouse
position without a visual component, first create a visual component.

--
Paul Lutus
http://www.arachnoid.com


Tor Iver Wilhelmsen 08-17-2004 02:17 PM

Re: Mouse position relative to screen
 
"MAB" <bad-email@nowhere.com> writes:

> The MouseMotionListener works relative to some component of the app
> but what if I have no visual component and I want the absolute
> position of the mouse?


Use java.awt.Robot to force it to be where you want it to be. :)

MAB 08-18-2004 04:50 AM

Re: Mouse position relative to screen
 

"Tor Iver Wilhelmsen" <tor.iver.wilhelmsen@broadpark.no> wrote in message
news:ud61palwo.fsf@broadpark.no...
> "MAB" <bad-email@nowhere.com> writes:
>
> > The MouseMotionListener works relative to some component of the app
> > but what if I have no visual component and I want the absolute
> > position of the mouse?

>
> Use java.awt.Robot to force it to be where you want it to be. :)


First I want to know where it is :)




MAB 08-18-2004 04:52 AM

Re: Mouse position relative to screen
 

"Paul Lutus" <nospam@nosite.zzz> wrote in message
news:10i449a5f0gfec6@corp.supernews.com...
> MAB wrote:
>
> > How do I get the position of the mouse relative to the top left of the
> > screen. The MouseMotionListener works relative to some component of the
> > app but what if I have no visual component and I want the absolute
> > position of the mouse?

>
> Basically, what the other posters are telling you is, to get the mouse
> position without a visual component, first create a visual component.
>


I want the absolute position of the mouse on screen. How would creating a
visual component help?



Paul Lutus 08-18-2004 06:04 AM

Re: Mouse position relative to screen
 
MAB wrote:

>
> "Paul Lutus" <nospam@nosite.zzz> wrote in message
> news:10i449a5f0gfec6@corp.supernews.com...
>> MAB wrote:
>>
>> > How do I get the position of the mouse relative to the top left of the
>> > screen. The MouseMotionListener works relative to some component of the
>> > app but what if I have no visual component and I want the absolute
>> > position of the mouse?

>>
>> Basically, what the other posters are telling you is, to get the mouse
>> position without a visual component, first create a visual component.
>>

>
> I want the absolute position of the mouse on screen. How would creating a
> visual component help?


For your answer, post your commmand-line (non-GUI) application that provides
the mouse's position on the screen.

--
Paul Lutus
http://www.arachnoid.com


MAB 08-18-2004 07:49 AM

Re: Mouse position relative to screen
 

"Paul Lutus" <nospam@nosite.zzz> wrote in message
news:10i5sc81pbstu6c@corp.supernews.com...
> MAB wrote:
>
> >
> > "Paul Lutus" <nospam@nosite.zzz> wrote in message
> > news:10i449a5f0gfec6@corp.supernews.com...
> >> MAB wrote:
> >>
> >> > How do I get the position of the mouse relative to the top left of

the
> >> > screen. The MouseMotionListener works relative to some component of

the
> >> > app but what if I have no visual component and I want the absolute
> >> > position of the mouse?
> >>
> >> Basically, what the other posters are telling you is, to get the mouse
> >> position without a visual component, first create a visual component.
> >>

> >
> > I want the absolute position of the mouse on screen. How would creating

a
> > visual component help?

>
> For your answer, post your commmand-line (non-GUI) application that

provides
> the mouse's position on the screen.
>
> --
> Paul Lutus
> http://www.arachnoid.com



I wrote a program (with no interface) that is able to click anywhere on the
screen repeatedly thus serving the needs I expressed in the previous thread
i.e. to click the OK button of the message that pops up every minute in the
game (actually my 3 year old kid plays the game and i'm doing this for him
and for myself (learning java)). The location (x,y) and the time interval
(d) between each click is supplied thru command line arguments. Here is the
program

import java.awt.* ;
import java.util.* ;

public final class ClickMouse extends TimerTask {
public static int x, y, d ;

public static void main(String[] args) {

TimerTask clikMouse = new ClickMouse();
Timer t = new Timer();

x = Integer.parseInt(args[0]) ;
y = Integer.parseInt(args[1]) ;
d = Integer.parseInt(args[2]) ;

t.schedule(clikMouse,1000,d*1000);
}

public void run() {

try {
Robot bot = new Robot();

bot.mouseMove(x,y);
bot.mousePress(java.awt.event.InputEvent.BUTTON1_M ASK );
bot.mouseRelease(java.awt.event.InputEvent.BUTTON1 _MASK);
}
catch (Exception e)
{
System.out.println("Exception occured :" + e.getMessage());
}

}


Now ideally I would like the program to end when my kid is finished with the
game so that the mouse is released and he can play any other game he wants.
The best way that comes to my mind (any other ideas are welcome but I just
dont want to make him click the mouse or press any key) is that when the
mouse is moved more than certain distance from the point (x,y) the program
should end i.e to release the mouse just move it far enough. For this my
program needs to determine the mouse position every time before clicking at
x,y ( I could put a flag to make sure it doesnt quit the first time it
clicks etc). So here is how things will go

1. My son starts the (keyboard based) game and this java app at the same
time
2. Every time the message box of the game pops up it will be closed by my
program within 2 seconds ( the position of the OK button is always the same
so my app would start always with the same arguments e.g javaw ClickMouse
"400" "500" "2"
I've checked this functionality and it works, now only the last part. When
he moves the mouse (which he will naturally) I want the program to end thus
releasing the mouse. for this, the app needs to know the absolute position
of the mouse so that it can compare it with x,y or just the relative
distance from x,y.






All times are GMT. The time now is 10:15 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.