當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino Mouse - Mouse.press()用法及代碼示例

將按鈕按下發送到連接的計算機。按下相當於單擊並連續按住鼠標按鈕。使用 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.cc大神的英文原創作品 Mouse - Mouse.press()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。