java code to click mouse and press keys?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: java code to click mouse and press keys?

  1. #1
    Join Date
    Jan 2005
    Posts
    2

    Question java code to click mouse and press keys?

    Hello there,

    Is it possble to write a java program that is able to press the mouse keys and/or press the keyboard keys by itself? (say "keypress.A" , "mouseclick.LEFT") If it can, which class should I use?

    Thank you very much

  2. #2
    Join Date
    Jan 2005
    Posts
    45
    Hello,

    Java provide a convenient API for emulating keyboard and mouse inputs.

    I suggest you to check the Robot's class : http://java.sun.com/j2se/1.4.2/docs/...awt/Robot.html
    Lionel Badiou
    CodeFutures -
    Java Code Generation

    http://www.codefutures.com



  3. #3
    Join Date
    Jan 2005
    Posts
    2
    Hi

    Thank you very your reply. I've tried using the robot class and the KeyEvent, but the KeyEvent seems only can press the key once, (say robot.keypress(KeyEvent.VK_LEFT) ) Is it possible to press a specific key for a period of time then release it? Moreover, I want to use this program after activating a certain window, say notepad1.txt, which class should I use to archieve that?

    Thank you

  4. #4
    Join Date
    Jan 2005
    Posts
    45
    Hi again,

    It sounds me that all you have to do is to press/release a key repeatedly for a period of time. I gess you could achieve this easily by using Swing timer:

    http://java.sun.com/docs/books/tutor...isc/timer.html

    Best regards,
    Lionel Badiou
    CodeFutures -
    Java Code Generation

    http://www.codefutures.com



  5. #5
    Join Date
    May 2004
    Posts
    219
    Would this work?
    Code:
    robot.keyPress(...);
    robot.delay(3000);
    robot.keyRelease(...);
    I've never used this class, but it looks like that's how it's designed...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center