🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #91

How to convert String to KeyInput for Robot

#91
From: 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);

  } 
Technical Details
Message-ID: <43cdd802$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,a488078dfbe2d772,start
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Daniel Mark" <daneilmarkhot@hotmail.com>
Newsgroups: borland.public.jbuilder.java.swing
Subject: How to convert String to KeyInput for Robot
Date: Tue, 17 Jan 2006 23:56:49 -0600
Lines: 41
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
NNTP-Posting-Host: 69.5.132.70
Message-ID: <43cdd802$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1137563650 69.5.132.70 (17 Jan 2006 21:54:10 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail