Mouse.press()

Last revision:2024/05/16

名称

Mouse.press()

説明

PCにマウス押下を送信する。これは、マウスボタンを押下したままにするのと等しい。押下状態はMouse.release()によってキャンセルされる。

Mouse.press()を使う前に、Mouse.begin()で通信を開始する必要がある。

Mouse.press()は、デフォルトでは、左ボタンを押下する。

書式

  • Mouse.press()
  • Mouse.press(button)

C言語シグネチャ(avr)

void Mouse_::press(uint8_t b = MOUSE_LEFT);

引数

buttonマウスのどのボタンを押すかを指定する。データ型: char
MOUSE_LEFT: 左ボタン(デフォルト)。
MOUSE_RIGHT: 右ボタン。
MOUSE_MIDDLE: 中ボタン。

戻り値

なし。

コード例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <Mouse.h>

void setup() {
  //The switch that will initiate the Mouse press
  pinMode(2, INPUT);
  //The switch that will terminate the Mouse press
  pinMode(3, INPUT);
  //initiate the Mouse library
  Mouse.begin();
}

void loop() {
  //if the switch attached to pin 2 is closed, press and hold the left mouse button
  if (digitalRead(2) == HIGH) {
    Mouse.press();
  }
  //if the switch attached to pin 3 is closed, release the left mouse button
  if (digitalRead(3) == HIGH) {
    Mouse.release();
  }
}

注意

Mouse.press()コマンドを使うと、Arduinoはマウスを横取りする。このコマンドを使う前に制御可能であることを確認すること。マウス制御状態をトグルする押しボタンを使うのが効果がある。

参照

オリジナルのページ

https://docs.arduino.cc/language-reference/en/functions/usb/Mouse/mousePress/

実装の解析

まだ解析していません。

最終更新日

August 16, 2026

inserted by FC2 system