当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Arduino Keyboard.println()用法及代码示例


说明

向连接的计算机发送一个或多个击键,然后按 Enter 键。

Keyboard.println() 必须在启动 Keyboard.begin() 之后调用。

用法

Keyboard.println()
Keyboard.println(character)
Keyboard.println(characters)

参数

character: 一个字符或 int 作为击键发送到计算机,然后按 Enter。
characters:要作为击键发送到计算机的字符串,然后按 Enter。

返回

发送的击键次数。数据类型:size_t

示例代码

#include <Keyboard.h>

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if (digitalRead(2) == LOW) {
    //Send the message
    Keyboard.println("Hello!");
  }
}

注意事项和警告

当您使用 Keyboard.println() 命令时,Arduino 将接管您的键盘!在使用该命令之前,请确保您有控制权。切换键盘控制状态的按钮有效。

相关用法


注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 Keyboard.println()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。