当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。