Results 1 to 7 of 7
  1. #1
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    135
    Rep Power
    0

    Default Get A Click From Anywhere On The Screen

    Hello, I am having a bit of a problem I wanted to make an auto clicker program for games and what not, but I can't figure out how to get a click from anywhere on the screen. I have seen ways to do it if you click the application, but I don't want that. If you could help me I would really appreciate it. Just so I don't get a "google is your friend" comment I have been researching it and can't figure out how to do it.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    If you are interested in having your program control the mouse and click anywhere, then you will want to check out the Robot class. The API for this class will tell you the methods that it has available. But having said that, I will also say that for me Java isn't the best programming language to use for driving other applications, mainly because Java distances itself from the operating system, and most driver apps will need to get close to the OS especially if they need to sense the response from the driven program. For Windows I've used AutoIt with some success.

  3. #3
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    135
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    If you are interested in having your program control the mouse and click anywhere, then you will want to check out the Robot class. The API for this class will tell you the methods that it has available. But having said that, I will also say that for me Java isn't the best programming language to use for driving other applications, mainly because Java distances itself from the operating system, and most driver apps will need to get close to the OS especially if they need to sense the response from the driven program. For Windows I've used AutoIt with some success.
    I was originally looking at the robot class and I figured out how to cause it to click using the robot class, but how would I go about getting it to tell if someone pressed the mouse.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by anthropamorphic View Post
    I was originally looking at the robot class and I figured out how to cause it to click using the robot class, but how would I go about getting it to tell if someone pressed the mouse.
    If you're talking about getting mouse information anywhere on the screen, I don't know that you can as this usually requires getting closer to the OS than Java likes. Again, other languages will do this better for you. Another option is JNI or the easier JNA to help you link Java to the OS's libraries. This will involve a bit of work on your part however.

  5. #5
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    135
    Rep Power
    0

    Default

    I will try and figure it out but I have no idea what jni or jna is

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by anthropamorphic View Post
    I will try and figure it out but I have no idea what jni or jna is
    Wikipedia has good sections on these guys to give you a brief overview of what they are, but even briefer they are libraries that allow your Java program communicate with a C or C++ program. Then Google for the tutorials on either if are brave enough to venture forward.

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,227
    Rep Power
    6

    Default

    but how would I go about getting it to tell if someone pressed the mouse.
    You need to listen for a MouseEvent. This is usually down by adding a MouseListener to a component. See How to Write a Mouse Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

    However, since you want to listen to all mouse events, you can check out: Global Event Listeners « Java Tips Weblog

Similar Threads

  1. Replies: 2
    Last Post: 06-22-2011, 01:19 PM
  2. Replies: 0
    Last Post: 05-04-2011, 09:35 PM
  3. How do I click somewhere on the screen?
    By Broodjie in forum Advanced Java
    Replies: 1
    Last Post: 03-21-2011, 10:17 PM
  4. Move from one screen fto other screen
    By jprgmr75 in forum CLDC and MIDP
    Replies: 0
    Last Post: 01-02-2011, 06:32 PM
  5. Blank Screen while navigating from one screen to another
    By mohana.krishna in forum Java Servlet
    Replies: 0
    Last Post: 03-03-2009, 05:03 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •