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

Thread: Track Mouse Movements

  1. #1
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Track Mouse Movements

    Hi

    Looking for some advice, I want to be able to record the mouse movement coordinates and record them each time the mouse moves or clicks.

    Now my idea is to run a java app in the background and then this will record the coordinates of the mouse when the user is using their programs so I can then use the coordinates to automate mouse movements and simulate clicks to automate tasks so obviously I need to be able to use all programs on the computer but to record the clicks and movements.

    I have looked and it seems there is a mouse listener which will achieve this however it seems to need to occur over a java component so I need a way to have a jFrame/Panel invisible and not in the way of the programs I am using so It can record the coordinates when using the other programs.

    Can anyone think of a way to achieve this?

    Thanks


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Track Mouse Movements

    Tracking mouse movements is easy enough with MouseInfo. It's a limited solution though because it won't handle click events. A hackish solution to grab click events would be to add a AWTEventListener to monitor system-wide AWT events. It's a problematic solution because if the app looses focus the events won't get picked up.

    Another, even more hackish solution would be to put a windowless, transparent JFrame over the entire screen and use that to monitor click/mouse moves. When a click even occurs, minimize the transparent window, use a Robot so that whatever is under the JFrame recieves the input then re-maximize the window. It will be more reliable than an AWTEventListener but jam packed full of gotcha's.

  3. The Following User Says Thank You to ChristopherLowe For This Useful Post:

    mds1256 (November 20th, 2013)

  4. #3
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Track Mouse Movements

    Thanks, looks like I could use this, just need to find a way so I can manipulate the application underneath whilst a semi-transparent jframe is on the whole screen. I tried the Robot as suggested and it works but there are lots of gotchas like you have mentioned so I guess it is just the case of working through them and finding a solution to each one when they turn up.

Similar Threads

  1. How cookies are used to track a session?
    By Chicharito in forum Java Servlet
    Replies: 1
    Last Post: June 9th, 2013, 01:04 PM
  2. How To Track A Moving Object
    By mahdi.nikoo in forum Algorithms & Recursion
    Replies: 7
    Last Post: November 2nd, 2012, 01:03 PM
  3. [SOLVED] Keeping Track
    By Nuggets in forum Loops & Control Statements
    Replies: 2
    Last Post: April 15th, 2012, 05:37 PM
  4. keep track of objects
    By keep smiling in forum Java Theory & Questions
    Replies: 4
    Last Post: February 20th, 2012, 03:44 PM
  5. Tracking mouse movements
    By wbroman in forum Java Theory & Questions
    Replies: 2
    Last Post: November 22nd, 2010, 04:24 PM