Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to get Mouse Click Position even if it is not within our application?

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to get Mouse Click Position even if it is not within our application?

    Hi I am interested how I can get mouse click position even if it is not within my application?. I know about MouseInfo class but its provide only mouse position but not click position. Is there any way in java to do get this info ?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,310
    My Mood
    Mellow
    Thanks
    194
    Thanked 669 Times in 656 Posts

    Default Re: How to get Mouse Click Position even if it is not within our application?

    You might find this discussion interesting.

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How to get Mouse Click Position even if it is not within our application?

    The MouseEvent may have some useful methods
    -Edit- Ya I missed the "not within my application" part

  4. #4
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    606
    My Mood
    Sleepy
    Thanks
    10
    Thanked 90 Times in 83 Posts

    Default Re: How to get Mouse Click Position even if it is not within our application?

    Quote Originally Posted by jps View Post
    The MouseEvent may have some useful methods
    Not outside the application. The only way I can think of is using a dll and JNI.

  5. The Following User Says Thank You to PhHein For This Useful Post:

    jps (August 28th, 2013)

  6. #5
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: How to get Mouse Click Position even if it is not within our application?

    Hello.
    No. You can do it without any ddl or jni.
      import java.awt.MouseInfo;
      import java.awt.Point;
      import java.awt.PointerInfo;
     
      PointerInfo inf = MouseInfo.getPointerInfo();
      Point p = inf.getLocation();
      System.out.println("(x,y):("+p.x+","+p.y+")");

    The source is here: swing - how to obtain mouse click coordinates outside my window in Java - Stack Overflow
    Just scroll down somewhere little below the middle.

    Syed.

Similar Threads

  1. [SOLVED] trying to change image by mouse click
    By leonne in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 5th, 2013, 07:16 PM
  2. How to get Mouse Position even if it is not within our application?
    By Freaky Chris in forum Java Programming Tutorials
    Replies: 2
    Last Post: January 4th, 2012, 09:57 AM
  3. trying to draw a circle at the location of every mouse click
    By jopeters in forum AWT / Java Swing
    Replies: 0
    Last Post: October 18th, 2011, 05:24 PM
  4. Directly Click the pdf File and my Java application will run
    By Jhovarie in forum Java Theory & Questions
    Replies: 2
    Last Post: May 3rd, 2011, 08:48 AM
  5. How to get Mouse Position even if it is not within our application?
    By Freaky Chris in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 29th, 2009, 12:41 PM