【发布时间】:2014-12-20 22:30:38
【问题描述】:
当使用 Arduino 作为键盘按下板上的按钮时,我想在 Windows 7 中访问 cmd:
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
char ctrlKey = KEY_LEFT_GUI;
void setup() {
// Initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// Initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// Read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
delay(1000);
Keyboard.press(ctrlKey);
Keyboard.press('r'); // This call runs
Keyboard.println("cmd"); // But here it won't write "cmd"
Keyboard.press('10');
Keyboard.releaseAll();
delay(1000);
}
else
{
digitalWrite(ledPin, LOW);
}
}
我还尝试了分别对每个字母使用 write()、print() 和 press() 方法,但它失败了。大多数情况下,它会最小化所有程序或邀请所有固定在 Windows 工具栏中的程序。
有什么问题?
【问题讨论】: