fake keyboard button pressed


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: fake keyboard button pressed

  1. #1
    Join Date
    Mar 2008
    Posts
    1

    fake keyboard button pressed

    i was wondering if it is possible to make the computer think a keyboard button was pressed though is wasn't?

    for example: the java program runs in the background and create these fake keyboard button events. let's say i'm currently viewing the internet explorer and it thinks the buttons were pressed and acts accordingly.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    For what purpose do you need this?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Apr 2008
    Posts
    1
    I think you can use the java.awt.Robot class. Let see this example:
    Code:
    import java.awt.Robot;
    import java.awt.event.KeyEvent;
    import java.io.*;
    
    public class Sample {
    	public static void main(String [] args) throws Exception
    	{
    		Robot robot = new Robot();
    		System.out.println("Hello World");
    		System.out.println("Enter a string...");
    		String s;
    		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    		s = br.readLine();
    		robot.keyPress(KeyEvent.VK_H);
    		robot.keyPress(KeyEvent.VK_E);
    		robot.keyPress(KeyEvent.VK_L);
    		robot.delay(50);
    		robot.keyPress(KeyEvent.VK_L);
    		robot.keyPress(KeyEvent.VK_O);
    		robot.keyPress(KeyEvent.VK_ENTER);
    		System.out.println(s);
    	}
    }

Similar Threads

  1. Pseudocode Problem
    By zobi316 in forum VB Classic
    Replies: 3
    Last Post: 03-10-2008, 07:05 AM
  2. Need help with calculator...
    By 2eXtreme in forum Java
    Replies: 0
    Last Post: 04-05-2006, 07:38 AM
  3. Replies: 2
    Last Post: 12-14-2005, 01:36 AM
  4. How do i know which button was pressed?
    By computerdude7 in forum Java
    Replies: 0
    Last Post: 01-24-2001, 02:54 PM
  5. Button pressed?
    By alex in forum Java
    Replies: 8
    Last Post: 01-01-2001, 01:30 AM

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