Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Robot class

 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
Is anyone here familiar with the robot class in java 1.3
i was wondering if i can type from the keyboard as well or can i just use the mouse
thank you
Fred
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you can simulate key-strokes as well as mouse movements/clicks using the Robot class.
Use keyPress(int keyCode) and keyRelease(int keyCode) methods where keyCode is one of several constants defined in the KeyEvent class, like KeyEvent.VK_J
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you - have you used it as i do not see that method in the api
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the API for 1.3


keyPress
public void keyPress(int keycode)
Presses a given key.
Key codes that have more than one physical key associated with them (e.g. KeyEvent.VK_SHIFT could mean either the left or right shift key) will map to the left key.
Parameters:
keyCode - Key to press (e.g. KeyEvent.VK_A)
Throws:
IllegalArgumentException - if keycode is not a valid key
----------------------------------------------------
keyRelease
public void keyRelease(int keycode)
Releases a given key.
Key codes that have more than one physical key associated with them (e.g. KeyEvent.VK_SHIFT could mean either the left or right shift key) will map to the left key.
Parameters:
keyCode - Key to release (e.g. KeyEvent.VK_A)
Throws:
IllegalArgumentException - if keycode is not a valid key

 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you
whats the diffrence between pressed and released?
do i have to press it and then release it ?

[This message has been edited by Fred Abbot (edited July 19, 2001).]
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You press the shift key and DON'T release and the press the "a" key to get a capital A. So the pattern is
Press shift
Press A
Release A
Release shift
Notice that a "Press A" and "Release A" together make a "typed A", however you can press and release shift all day and nothing will get typed, some keys are typing keys and some are not.
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so if i just wanted a lower case letter i would just use keyPressed(virtual key ...)?
or do i have to press it and then release it

[This message has been edited by Fred Abbot (edited July 19, 2001).]
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I was not sure how the Robot class handles it - so I ran a test with this code. I just threw it in with some other stuff that I had laying around - so ignore the other stuff:

So the answer seems to be NO, just a keyPress will get it to type.
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic