在Java中注入按键 [英] Inject a keystroke in java

查看:115
本文介绍了在Java中注入按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将击键注入OS键盘输入缓冲区的方法, 例如,当您单击按钮时,程序将插入一个(或多个)键盘击键.我想在Java中执行此操作,因为我想在(win,linux和osx)中运行它.我想我将不得不使用JNI,有人有什么想法吗?

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?

感谢所有stackoverflowers;)

Thanks all stackoverflowers ;)

推荐答案

我的猜测是java.awt.Robot类将为您做到这一点:

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

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

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

java.awt.Robot用于生成本机系统输入事件,用于测试自动化,自运行演示以及需要控制鼠标和键盘的其他应用程序."

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."

这篇关于在Java中注入按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆