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
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
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
"JavaRanch, where the deer and the Certified play" - David O'Meara
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.
"JavaRanch, where the deer and the Certified play" - David O'Meara
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.
"JavaRanch, where the deer and the Certified play" - David O'Meara