Keyboard.press()

Last revision:2024/05/15

名称

Keyboard.press()

説明

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

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

書式

Keyboard.press(key)

C言語シグネチャ(avr)

size_t Keyboard_::press(uint8_t k);

引数

key押すキー。データ型: char

戻り値

送信したバイト数。

コード例

 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://docs.arduino.cc/language-reference/en/functions/usb/Keyboard/keyboardPress/

実装の解析

まだ解析していません。

最終更新日

July 20, 2026

inserted by FC2 system