Mouse.isPressed()

名称

Mouse.isPressed()

説明

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

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

書式

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

引数

bマウスのどのボタンを調べるかを指定する。
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);
}

参照

言語 Mouse.click()

言語 Mouse.end()

言語 Mouse.move()

言語 Mouse.press()

言語 Mouse.release()

オリジナルのページ

https://www.arduino.cc/reference/en/language/functions/usb/mouse/mouseispressed/

Last Revision: 2019/02/21

実装の解析

まだ解析していません。

最終更新日

January 4, 2024

inserted by FC2 system