说明
检查所有鼠标按钮的当前状态,并报告是否按下了任何按钮。
用法
Mouse.isPressed();
Mouse.isPressed(button);
参数
当没有传递值时,它会检查鼠标左键的状态。
button
:要检查哪个鼠标按钮。允许的数据类型:char
。
-
MOUSE_LEFT (default)
-
MOUSE_RIGHT
-
MOUSE_MIDDLE
返回
报告按钮是否被按下。数据类型:bool
。
示例代码
#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);
}
相关用法
- Arduino Mouse.begin()用法及代码示例
- Arduino Mouse.end()用法及代码示例
- Arduino Mouse.click()用法及代码示例
- Arduino Mouse.press()用法及代码示例
- Arduino Mouse.release()用法及代码示例
- Arduino Mouse.move()用法及代码示例
- Arduino Mouse - Mouse.click()用法及代码示例
- Arduino Mouse - Mouse.press()用法及代码示例
- Arduino Mouse - Mouse.isPressed()用法及代码示例
- Arduino Mouse - Mouse.end()用法及代码示例
- Arduino Mouse - Mouse.begin()用法及代码示例
- Arduino Mouse - Mouse.move()用法及代码示例
- Arduino Mouse - Mouse.release()用法及代码示例
- Arduino MKRGSM - gprs.attachGPRS()用法及代码示例
- Arduino MKRGSM - sms.read()用法及代码示例
- Arduino MKRNB - getCurrentCarrier()用法及代码示例
- Arduino MKRWAN - available()用法及代码示例
- Arduino MKRNB - getIMEI()用法及代码示例
- Arduino MKRWAN - version()用法及代码示例
- Arduino MKRGSM - sms.print()用法及代码示例
- Arduino MKRNB - endSMS()用法及代码示例
- Arduino MKRGSM - client.connected()用法及代码示例
- Arduino MKRGSM - voice.answerCall()用法及代码示例
- Arduino MKRGSM - voice.hangCall()用法及代码示例
- Arduino MKRGSM - sms.write()用法及代码示例
注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 Mouse.isPressed()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。