开发者

Inject a keystroke in java

开发者 https://www.devze.com 2023-01-13 03:31 出处:网络
I\'m looking for a way to inject a keystroke into the OS keyboard input buffer, like when you click a button the program inserts one (or more) keyboard strokes. I wanted to do this in java because I开

I'm looking for a way to inject a keystroke into the OS keyboard input buffer, like when you click a button the program inserts one (or more) keyboard strokes. I wanted to do this in java because I开发者_如何学编程 want to run this in (win,linux and osx). I guess that I'll have to make use of the JNI, do anyone have some ideas?

Thanks all stackoverflowers ;)


My guess is that the java.awt.Robot class will do this for you:

new Robot().keyPress(...);

http://download.oracle.com/javase/6/docs/api/java/awt/Robot.html#keyPress(int)

java.awt.Robot "is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed."


Check java Robot . I believe this is what you are looking for.

Also check this out. Example

0

精彩评论

暂无评论...
验证码 换一张
取 消