Keyboard.press()

名称

Keyboard.press()

説明

呼ばれると、Keyboard.press()は、キーボードが押され続けているように機能する。修飾キーとともに使うと有用である。押下状態を終えるには、Keyboard.release()もしくはKeyboard.releaseAll()を利用する。

Keyboard.press()を使う前に、Keyboard.begin()を呼ぶ必要がある。

書式

size_t Keyboard_::press(uint8_t k);

引数

k押すキー。

戻り値

送信したバイト数。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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);
}

参照

オリジナルのページ

https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardpress/

Last Revision: 2019/02/21

実装の解析

まだ解析していません。

最終更新日

January 4, 2024

inserted by FC2 system