檢查所有鼠標按鈕的當前狀態,並報告是否按下了任何按鈕。默認情況下,它會檢查鼠標左鍵的狀態。
用法
Mouse.isPressed();
Mouse.isPressed(button);
參數
button
:釋放了哪個鼠標按鈕(MOUSE_LEFT、MOUSE_RIGHT 或 MOUSE_MIDDLE,默認為 MOUSE_LEFT)。
返回
1 如果按鈕被按下,0 如果沒有。
示例
#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);
// Initialize 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 - Mouse.click()用法及代碼示例
- Arduino Mouse - Mouse.press()用法及代碼示例
- Arduino Mouse - Mouse.end()用法及代碼示例
- Arduino Mouse - Mouse.begin()用法及代碼示例
- Arduino Mouse - Mouse.move()用法及代碼示例
- Arduino Mouse - Mouse.release()用法及代碼示例
- Arduino Mouse.begin()用法及代碼示例
- Arduino Mouse.end()用法及代碼示例
- Arduino Mouse.click()用法及代碼示例
- Arduino Mouse.press()用法及代碼示例
- Arduino Mouse.isPressed()用法及代碼示例
- Arduino Mouse.release()用法及代碼示例
- Arduino Mouse.move()用法及代碼示例
- 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 - Mouse.isPressed()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。