🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
1 messages
1 total messages Started by Daniel Mark Wed, 18 Jan 2006 05:56
How to convert String to KeyInput for Robot
#91
Author: Daniel Mark
Date: Wed, 18 Jan 2006 05:56
39 lines
1710 bytes
Hello all:

I use the following snippet to demo how to write down a string on some place 
of screen.

For example: If I want to write down 'robot', I have to get the array 
keyInput first.

My question is to find an easy to automatically convert a given string to 
corresponding
keyInput.

Does java provide such function for us?



Thank you
-Daniel


//Store Keystrokes in an array
                   static int keyInput[] = {KeyEvent.VK_R,KeyEvent.VK_O,
                      KeyEvent.VK_B,KeyEvent.VK_O,KeyEvent.VK_T};

Robot robot = new Robot();

  //This types the word 'robot' in the Textarea
  for (int i = 0; i < keyInput.length; i++)
  {
   if(i > 0)
     {
               robot.keyRelease(KeyEvent.VK_SHIFT);
   }

          robot.keyPress(keyInput[i]);

   robot.delay(500);

  } 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads