我有三个按钮,如果没有按下,它将在0和2之间给出值,如果按下则在999到1000之间。
我可以用java和all来读它,但是如果按下其中一个按钮,我想模拟键盘键。
是否有类似isKeyboardKey(LEFT)的东西;它代表Java中的键盘键?
示例:
String key_enter;
String key_left;
String key_right;
if ( sensorValue1 > 100 )
{
key_enter = ENTER; // it will simulate ENTER ( work like regular enter button), so if Word or Notepad is open and the program runs, it will go to new line like a normal ENTER hit.
} else if (sensorValue2 > 100 )
{
key_left = LEFT; // will work like regular left keyboard button
} else if ( sensorValue 3 > 100 )
{
key_right = RIGHT; // will work like regular right keyboard button
} else { System.out.print("No sensor value"); }
答案 0 :(得分:0)
使用java.awt.Robot
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}