Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Mouse position relative to screen

Reply
Thread Tools

Mouse position relative to screen

 
 
KC Wong
Guest
Posts: n/a
 
      08-18-2004
> 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.


Check out this thread I found by Googling "Java mouse absolute position":
(Pls concat the long link if broken)
http://groups.google.com/groups?hl=e....de%26rnum%3D5

It has the answer - but only if the program has any GUI components. In your
case, your application has no GUI - thus no component to catch the mouse
event.

I'm watching this thread, waiting for an answer too...


 
Reply With Quote
 
 
 
 
Adam
Guest
Posts: n/a
 
      08-18-2004

"MAB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?


AFAIK MouseEvents are generated by AWT,
when Event Dispatch Thread is running.
I don't know a way of starting the EDT
without having any visual component created.

When I was researching this issue - I failed
to get a solution (capturing mouse events
in a non-GUI app).

So my answer would be : no way in pure Java
to capture mouse events happening outside of
a Java visual components.

Probably could be written in C++, using WinAPI
and then used in Java with JNI.

Adam


 
Reply With Quote
 
 
 
 
Paul Lutus
Guest
Posts: n/a
 
      08-18-2004
MAB wrote:

>> > 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.

>
> I wrote a program (with no interface) that is able to click anywhere on
> the screen repeatedly


And you have just left the stated topic, which is to locate the mouse
cursor's current position on the screen, a passive monitoring function.
Your application puts the mouse cursor at a determined location, it doesn't
read its current position.

> thus serving the needs I expressed in the previous
> thread i.e. to click the OK button


A total departure from this thread's topic. Here is the first line of the
first post:

> How do I get the position of the mouse relative to the top left of the
> screen


It is really a good idea to read a thread before posting to it.

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

 
Reply With Quote
 
Paul Lutus
Guest
Posts: n/a
 
      08-18-2004
KC Wong wrote:

/ ...

> I'm watching this thread, waiting for an answer too...


The answer is that you cannot read the mouse's position without a visual
component. The poster identified as MAB is confusing writing a mouse
position with reading it.

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

 
Reply With Quote
 
MAB
Guest
Posts: n/a
 
      08-18-2004

"Paul Lutus" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> MAB wrote:
>
> >> > 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.

> >
> > I wrote a program (with no interface) that is able to click anywhere on
> > the screen repeatedly

>
> And you have just left the stated topic, which is to locate the mouse
> cursor's current position on the screen, a passive monitoring function.
> Your application puts the mouse cursor at a determined location, it

doesn't
> read its current position.
>
> > thus serving the needs I expressed in the previous
> > thread i.e. to click the OK button

>
> A total departure from this thread's topic. Here is the first line of the
> first post:
>
> > How do I get the position of the mouse relative to the top left of the
> > screen

>
> It is really a good idea to read a thread before posting to it.
>


its even a better idea to read a post before replying to it. Read the full
post. I explained what I had accomplished and what I wanted to do now and
why I wanted to do it ( locate the mouse position )


 
Reply With Quote
 
MAB
Guest
Posts: n/a
 
      08-18-2004

"Paul Lutus" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> KC Wong wrote:
>
> / ...
>
> > I'm watching this thread, waiting for an answer too...

>
> The answer is that you cannot read the mouse's position without a visual
> component. The poster identified as MAB is confusing writing a mouse
> position with reading it.
>


I'm not confusing anything. I wrote a program that could write a mouse
position and now I want to add the capability to read also. Make it a habit
to read a post carefully before replying to it.


 
Reply With Quote
 
Paul Lutus
Guest
Posts: n/a
 
      08-18-2004
MAB wrote:

>
> "Paul Lutus" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> MAB wrote:
>>
>> >> > I want the absolute position of the mouse on screen. How would

> creating
>> > a
>> >> > visual component help?


[ clearly a question about READING the mouse cursor position ]

[ essential text snipped here by MAB ]

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


[ a challenge to READ the mouse cursor position without a visual component ]

>> >
>> > I wrote a program (with no interface) that is able to click anywhere on
>> > the screen repeatedly


[ an abrupt change of topic from READING the mouse cursor potion to SETTING
the mouse cursor position ]

>>
>> And you have just left the stated topic, which is to locate the mouse
>> cursor's current position on the screen, a passive monitoring function.
>> Your application puts the mouse cursor at a determined location, it

> doesn't
>> read its current position.
>>
>> > thus serving the needs I expressed in the previous
>> > thread i.e. to click the OK button

>>
>> A total departure from this thread's topic. Here is the first line of the
>> first post:
>>
>> > How do I get the position of the mouse relative to the top left of the
>> > screen

>>
>> It is really a good idea to read a thread before posting to it.
>>

>
> its even a better idea to read a post before replying to it. Read the full
> post. I explained what I had accomplished and what I wanted to do now and
> why I wanted to do it ( locate the mouse position )


You clearly cannot grasp the meaning of your own posts.

The original request:

>> How do I get the position of the mouse relative to
>> the top left of the screen.


This is a request for a method to READ the mouse cursor position.

Your later post:

>> 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


This is a statement that one can SET the mouse cursor position.

This is not the present topic.

Again, for those readers who might now be getting confused, one cannot read
the mouse cursor position without creating a visual component.

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

 
Reply With Quote
 
Paul Lutus
Guest
Posts: n/a
 
      08-18-2004
MAB wrote:

>
> "Paul Lutus" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> KC Wong wrote:
>>
>> / ...
>>
>> > I'm watching this thread, waiting for an answer too...

>>
>> The answer is that you cannot read the mouse's position without a visual
>> component. The poster identified as MAB is confusing writing a mouse
>> position with reading it.
>>

>
> I'm not confusing anything.


You most certainly are. Your original request:

>> How do I get the position of the mouse relative to
>> the top left of the screen.


This is very clearly a request to READ the mouse cursor position. We replied
that you cannot do this without creating a visual component. You disagreed
with this statement. We then asked that you post yoru code that can READ
the mouse cursor position without a visual component. You replied that you
ccould WRITE the mouse cursor position without a visual component, thus
confirming your total confusion.

Here it is again:

> I wrote a program that could write a mouse
> position and now I want to add the capability to read also.


As we have repeatedly pointed out, you need to have a visual component to do
this.

> Make it a
> habit to read a post carefully before replying to it.


It is your turn to try to read and understand the thread you started.

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

 
Reply With Quote
 
Carl Howells
Guest
Posts: n/a
 
      08-18-2004
MAB wrote:

> its even a better idea to read a post before replying to it. Read the full
> post. I explained what I had accomplished and what I wanted to do now and
> why I wanted to do it ( locate the mouse position )


Don't bother arguing with Paul. It's pointless. Once he's made up his
mind, no amount of evidence, logic, or yelling can change it.

But, his advice is usually correct. And while he's doing more yelling
at you than pointing out the issue, his advice is correct in this case,
too. There's no API to get the mouse position without creating a GUI
component. So, you're going to have to create a GUI component.

And if you're doing that, you might as well just put a "Quit" button on
it, and forget about reading the mouse position.
 
Reply With Quote
 
Thomas G. Marshall
Guest
Posts: n/a
 
      08-18-2004
Adam <(E-Mail Removed)> coughed up the
following:
> "MAB" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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?

>
> AFAIK MouseEvents are generated by AWT,
> when Event Dispatch Thread is running.
> I don't know a way of starting the EDT
> without having any visual component created.
>
> When I was researching this issue - I failed
> to get a solution (capturing mouse events
> in a non-GUI app).
>
> So my answer would be : no way in pure Java
> to capture mouse events happening outside of
> a Java visual components.
>
> Probably could be written in C++, using WinAPI
> and then used in Java with JNI.


So long as you keep it to a method call(s). JNI doesn't let you peer into
C++ objects.


--
It'salwaysbeenmygoalinlifetocreateasignaturethaten dedwiththeword"blarphoogy"
..


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse position in both fixed and relative positioning Nikolai Prokoschenko Javascript 2 05-18-2011 11:25 AM
Screen Capture With Mouse , Mouse Position Capture Max Java 7 08-08-2009 11:51 PM
Zoom relative to mouse position Amir Kouchekinia Java 6 05-23-2008 03:28 AM
Where is Form Relative Position and Absolute Position in VS.Net 2005 ? Luqman ASP .Net 1 02-07-2006 10:27 AM
iframe relative mouse position madmike Javascript 2 07-17-2003 06:58 PM



Advertisments