gpt4 book ai didi

java - 休息;然后继续;在 java

转载 作者:行者123 更新时间:2023-11-29 07:12:16 25 4
gpt4 key购买 nike

<分区>

我有一个代码,它从 button 中获取一个值,然后输出一些东西。如果我不使用 break;然后我按下 left button,它会输出 thousands of left。 enterright 相同。

我不是 Java 大师,几周前我才开始使用 Java 编程。

我希望我的代码永远不会停止阅读 按钮值,但我不希望我的代码在 时输出数千个左、右或输入>按钮被按下。我怎样才能做到这一点?此代码有效,但在我按下一个按钮 后停止。如果我向左按按钮,它会向左输出一次,然后停止运行。没有休息;它将输出数千。

for (int i = 0; ; i++) {

// Get the data from analog input 5
int sensorValue1 = phidget.getSensorValue(1);
int sensorValue2 = phidget.getSensorValue(2);
int sensorValue3 = phidget.getSensorValue(3);

if (sensorValue1 > 100 || sensorValue2 > 100 || sensorValue3 > 100){
// printing value
//System.out.println("sensorValue1 = " + sensorValue1 + ", sensorValue2 = " + sensorValue2 + ", sensorValue3 = " + sensorValue3 + ", Count = " + i);
if (sensorValue1 > 100){

System.out.println("RIGHT");

// simulates RIGHT key
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_RIGHT);
} catch (AWTException e) {
e.printStackTrace();
}
break;

} else if (sensorValue2 > 100)
{
System.out.println("LEFT");

// simulates LEFT key
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_LEFT);
} catch (AWTException e) {
e.printStackTrace();
}
break;
} else if (sensorValue3 > 100)
{
System.out.println("ENTER");

// simulates ENTER key
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
break;
}
} else {}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com