使用机器人在Java中键入字符 [英] Use a robot to type characters in Java

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

问题描述

我知道如何让机器人像这样模拟Y按键:

I know how to have Robot simulate a Y keypress like so:

    Robot.keyPress(KeyEvent.VK_Y);

但我如何让机器人按报价和期限?:

But how do I get Robot to press a quote and period?:

".  

任何人都可以提供一些参考页面或示例代码?

Can anyone provide me some reference page or sample code?

推荐答案

您不能总是只使用KeyEvent.VK ...变量。

You can't always just use the KeyEvent.VK... variable.

例如,在我的键盘上,%字符位于5之上。要使用机器人键入5,代码将是:

For example on my keyboard the "%" character is above the "5". To use a Robot to type a "5", the code would be:

robot.keyPress(KeyEvent.VK_5); 
robot.keyRelease(KeyEvent.VK_5);

并使用机器人输入%,代码为:

and use a Robot to type a "%", the code would be:

robot.keyPress(KeyEvent.VK_SHIFT); 
robot.keyPress(KeyEvent.VK_5); 
robot.keyRelease(KeyEvent.VK_5);
robot.keyRelease(KeyEvent.VK_SHIFT);

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

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