Kyle
Kyle

Reputation: 3042

(C#)SendKeys.SendWait("{TAB}"); in java?

In C# it's SendKeys.SendWait("{TAB}");

What is that in java? (Sending the TAB keystroke) ?

I couldn't find a real answer in java and java docs didn't know what I was asking. (I'm notice at terms).

Thank youuu favorite site. =)

EDIT: I'm trying to send a tab key to an open notepad document to draw an ASCII picture and I just wanted a tab key instead of 3 spaces.

Upvotes: 0

Views: 1793

Answers (2)

user85421
user85421

Reputation: 29680

Have a look at the java.awt.Robot class.
It can be used to send keystrokes (simulate keyboard):

Robot robot = new Robot();  // AWTException if not supported
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(20);
robot.keyRelease(KeyEvent.VK_TAB);

This will send TAB to the active application/window.

Upvotes: 4

camickr
camickr

Reputation: 324108

Component.transferFocus();

Or maybe you are looking for the KeyboardFocusManager focusNextComponent(...) method.

You can also use Component.dispatchEvent(...) where you create you own Tab KeyEvent.

I'm trying to send a tab key to an open notepad document

Then you would need to use the Robot class. The above approaches are for using within a Java application, not an external application.

Upvotes: -1

Related Questions