【问题标题】:Arduino Leonardo keyboard cmdArduino Leonardo 键盘 cmd
【发布时间】:2014-12-20 22:30:38
【问题描述】:

当使用 Arduino 作为键盘按下板上的按钮时,我想在 Windows 7 中访问 c​​md:

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 工具栏中的程序。

有什么问题?

【问题讨论】:

    标签: keyboard arduino


    【解决方案1】:

    您的代码按 SuperRSuperCSuperMSuperD,然后是Super以及一些空键。您需要在尝试填充文本框之前释放 Super,并且在填充后您需要按 Enter 而不是那个奇怪的键。

    【讨论】:

    • 啊哈,这就是重点。关于输入,我找不到输入 link 的 arduino 键盘修饰符。
    • '\n'"\n" 作为字符串的(一部分)。
    • 键盘类中的 print() 方法有问题。我有Keyboard.print("echo 0.0.0.0 websitename.com >> %WINDIR%\\system32\\drivers\\etc\\hosts"); ,结果是echo 0.0.0.0 websitename.com :: %WINDIR%zszstem32zdriverszetczhosts,但我想打印echo 0.0.0.0 websitename.com >> %WINDIR%\system32\drivers\etc\hosts
    猜你喜欢
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多