當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino Keyboard.print()用法及代碼示例

說明

向連接的計算機發送一個或多個擊鍵。

Keyboard.print() 必須在啟動 Keyboard.begin() 之後調用。

用法

Keyboard.print(character)
Keyboard.print(characters)

參數

character: 一個字符或 int 作為擊鍵發送到計算機。
characters:要作為擊鍵發送到計算機的字符串。

返回

發送的擊鍵次數。數據類型: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.print("Hello!");
  }
}

注意事項和警告

當您使用Keyboard.print() 命令時,Arduino 將接管您的鍵盤!在使用該命令之前,請確保您有控製權。切換鍵盤控製狀態的按鈕有效。

相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 Keyboard.print()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。