將按鈕按下發送到連接的計算機。按下相當於單擊並連續按住鼠標按鈕。使用 Mouse.release()
取消按下。在使用 Mouse.press()
之前,您需要與 Mouse.begin()
開始通信。 Mouse.press()
默認為左鍵按下。
用法
Mouse.press()
Mouse.press(button)
參數
button
:按下哪個鼠標按鈕(MOUSE_LEFT、MOUSE_RIGHT 或 MOUSE_MIDDLE,默認為 MOUSE_LEFT)。
返回
None。
示例
#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);
// Initialize 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 會接管您的鼠標!在使用該命令之前,請確保您有控製權。切換鼠標控製狀態的按鈕是有效的。
相關用法
- Arduino Mouse - Mouse.click()用法及代碼示例
- Arduino Mouse - Mouse.isPressed()用法及代碼示例
- 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.press()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。