Results 1 to 19 of 19

Thread: Mouse

  1. #1
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Mouse

    How can I create something like a second mouse that can control my application without taking over the real mouse?

    If you are wondering what I am doing - I am trying to make something like a bot.
    Last edited by PhQ; 08-17-2010 at 04:50 PM.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Why would you want to do that? This smells like a design flaw.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    It seems to me you would need to replicate the signal your operating system sends to programs when the mouse does things. Without some specialized tools, that is going to be very hard.

  4. #4
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    So... How can I do this?

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    If you're trying to mess with non Java windows, use C++ or some other language being closer to the OS.
    Java is the wrong choice for such tasks.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  6. #6
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by PhHein View Post
    If you're trying to mess with non Java windows, use C++ or some other language being closer to the OS.
    Java is the wrong choice for such tasks.
    There are java bots for games that use the mouse thing but I don't know how to do it.

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Did you have a look at java.awt.Robot ?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    You could create your own mouse events and post them to the event queue.

  9. #9
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by Norm View Post
    You could create your own mouse events and post them to the event queue.
    This is going to move the real mouse.

  10. #10
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Then you should ask the authors of the bots you have seen, how they did it, instead of asking here without providing any information what you're trying to do. Bye.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  11. #11
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by PhHein View Post
    Then you should ask the authors of the bots you have seen, how they did it, instead of asking here without providing any information what you're trying to do. Bye.
    The first post tells you what I want to do.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    This is going to move the real mouse.
    How would passing objects around between components move the mouse?
    What it would do is fool the listening components into thinking that a mouse event had occurred.

  13. #13
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by Norm View Post
    How would passing objects around between components move the mouse?
    What it would do is fool the listening components into thinking that a mouse event had occurred.
    Nooo I need it to be a mouse, because, I am trying to make a bot for an browser game, so it can go around the site and get xp while I am doing something else with the pc (watching a film or something)

  14. #14
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Not with Java!
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    I don't get the concept of what you are trying to do?
    Sounds like you want to have two cursors, one the moved by a program and one by the user.
    Nooo I need it to be a mouse
    What is "a mouse"? In a program its the receipt of mouse events. There is no "visual" image of a cursor moving over a screen for a program.

    so it can go around the site and get xp
    Can you explain this. What is the "it"? A cursor?
    What is the "xp"?

  16. #16
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by Norm View Post
    I don't get the concept of what you are trying to do?
    Sounds like you want to have two cursors, one the moved by a program and one by the user.
    There should be one cursor (the normal cursor) and there should be an invisible cursor for the program and if the program is minimised the invisible cursor will still do things in the program.
    Quote Originally Posted by Norm View Post
    What is "a mouse"? In a program its the receipt of mouse events. There is no "visual" image of a cursor moving over a screen for a program.
    Yes, There should be no "visual" image of a cursor moving over a screen for a program.

    Quote Originally Posted by Norm View Post
    Can you explain this. What is the "it"? A cursor?
    What is the "xp"?
    It = invisible cursor
    xp = the experience for the game.
    Last edited by PhQ; 08-18-2010 at 04:23 PM.

  17. #17
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    How would you implement an "invisible cursor" for a program?
    You create mouse events and pass them to the program. The program doesn't know where the mouse events came from and would assume that the "mouse" sent them.

  18. #18
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by Norm View Post
    How would you implement an "invisible cursor" for a program?
    You create mouse events and pass them to the program. The program doesn't know where the mouse events came from and would assume that the "mouse" sent them.
    What kind of mouse events and how can I make those mouse events?

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    Do some research on the MouseEvent class.
    You create an instance of the class the same as with any other class.
    Use new and give the constructor some args.

    The trick is to put the mouse event object into the EventQueue for the app.

    Here's some code I wrote for AWT several years ago to allow the pressing of the Enter key to be handled like a mouse click on a button, ie it passes an ActionEvent to the button. Don't know if it works with Swing.
    Java Code:
    // MakeEnterDoAction.java
    // Class to turn key press into an ActionEvent for a component
    // A new instance of this class should be added as a KeyListener to the component
    // that is to receive the ActionEvent:      button.addKeyListener(new MakeEnterDoAction());
    
    
    package NormsTools;
    
    import java.awt.event.*;
    import java.awt.*;
    
    public class MakeEnterDoAction  extends KeyAdapter {
    
       public void keyPressed(KeyEvent ke) {
         if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
             Object src = ke.getSource();
             Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
                             new ActionEvent(src, 
                             ActionEvent.ACTION_PERFORMED, 
                             "Enter"));
         }
       }  // end keyPressed()
    }  // end class

Similar Threads

  1. Mouse Listener for mouse floating over object?
    By Krooger in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 05:34 AM
  2. Getting mouse coordinates
    By nishant.4545 in forum Advanced Java
    Replies: 3
    Last Post: 07-21-2009, 12:28 AM
  3. drawing with mouse
    By aveek in forum Java 2D
    Replies: 1
    Last Post: 06-27-2009, 02:38 PM
  4. Mouse events, are they best or only way to go?
    By dbashby in forum New To Java
    Replies: 2
    Last Post: 04-10-2009, 05:34 PM
  5. Mouse over JButton
    By sandor in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2007, 10:15 PM

Posting Permissions

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