說明
調用時,Keyboard.press()
的作用就像在鍵盤上按下並按住一個鍵。使用 modifier keys 時很有用。要結束按鍵,請使用 Keyboard.release() 或 Keyboard.releaseAll() 。
在使用 press()
之前必須調用 Keyboard.begin() 。
用法
Keyboard.press(key)
參數
key
:要按下的鍵。允許的數據類型:char
。
返回
發送的按鍵次數。數據類型:size_t
。
示例代碼
#include <Keyboard.h>
// use this option for OSX:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux:
// char ctrlKey = KEY_LEFT_CTRL;
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);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);
// new document:
Keyboard.press(ctrlKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(1000);
}
相關用法
- Arduino Keyboard.println()用法及代碼示例
- Arduino Keyboard.print()用法及代碼示例
- Arduino Keyboard.releaseAll()用法及代碼示例
- Arduino Keyboard.write()用法及代碼示例
- Arduino Keyboard.begin()用法及代碼示例
- Arduino Keyboard.release()用法及代碼示例
- Arduino Keyboard.end()用法及代碼示例
- Arduino long用法及代碼示例
- Arduino Arduino_EMBRYO_2 - setLengthXY()用法及代碼示例
- Arduino ~用法及代碼示例
- Arduino ArduinoBLE - bleDevice.advertisedServiceUuidCount()用法及代碼示例
- Arduino const用法及代碼示例
- Arduino Ethernet - server.begin()用法及代碼示例
- Arduino ArduinoBLE - BLEService()用法及代碼示例
- Arduino digitalWrite()用法及代碼示例
- Arduino ArduinoBLE - bleCharacteristic.subscribe()用法及代碼示例
- Arduino Servo - attach()用法及代碼示例
- Arduino write()用法及代碼示例
- Arduino Arduino_LSM9DS1 - readGyroscope()用法及代碼示例
- Arduino ArduinoSound - FFTAnalyzer.input()用法及代碼示例
- Arduino MKRGSM - gprs.attachGPRS()用法及代碼示例
- Arduino WiFiNINA - WiFi.config()用法及代碼示例
- Arduino MKRGSM - sms.read()用法及代碼示例
- Arduino MKRNB - getCurrentCarrier()用法及代碼示例
- Arduino Scheduler - Scheduler.startLoop()用法及代碼示例
注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 Keyboard.press()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。