Mouse.isPressed()

Last revision:2024/05/16

名称

Mouse.isPressed()

説明

Mouse.isPressed()は、デフォルトでは(引数を与えない場合は)、左ボタンの状態を調べる。

書式

  • Mouse.isPressed();
  • Mouse.isPressed(button);

C言語シグネチャ(avr)

bool Mouse_::isPressed(uint8_t b = MOUSE_LEFT);

引数

指定したマウスボタンの現在の状態を調べ、押されているのかそうでないのかを調べる。

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

戻り値

ボタンが押されていればtrue、そうでなければfalse。

コード例

 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 <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);
  //Start serial communication with the computer
  Serial.begin(9600);
  //initiate the Mouse library
  Mouse.begin();
}

void loop() {
  //a variable for checking the button's state
  int mouseState = 0;
  //if the switch attached to pin 2 is closed, press and hold the left mouse button and save the state ina  variable
  if (digitalRead(2) == HIGH) {
    Mouse.press();
    mouseState = Mouse.isPressed();
  }
  //if the switch attached to pin 3 is closed, release the left mouse button and save the state in a variable
  if (digitalRead(3) == HIGH) {
    Mouse.release();
    mouseState = Mouse.isPressed();
  }
  //print out the current mouse button state
  Serial.println(mouseState);
  delay(10);
}

参照

オリジナルのページ

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

実装の解析

まだ解析していません。

最終更新日

August 16, 2026

inserted by FC2 system