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


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

說明

發送一條消息,說明先前按下的按鈕(通過 Mouse.press() 調用)已釋放。 Mouse.release() 默認為左鍵。

用法

Mouse.release()
Mouse.release(button)

參數

button :按下哪個鼠標按鈕。允許的數據類型:char

  • MOUSE_LEFT(默認)

  • MOUSE_RIGHT

  • MOUSE_MIDDLE

返回

示例代碼

#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);
  //initiate 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.release() 命令時,Arduino 會接管您的鼠標!在使用該命令之前,請確保您有控製權。切換鼠標控製狀態的按鈕是有效的。

相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 Mouse.release()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。