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


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


说明

将按钮按下发送到连接的计算机。按下相当于单击并连续按住鼠标按钮。使用 Mouse.release() 取消印刷。

在使用 Mouse.press() 之前,您需要与 Mouse.begin() 开始通信。

Mouse.press() 默认为左键按下。

用法

Mouse.press()
Mouse.press(button)

参数

button :按下哪个鼠标按钮。允许的数据类型:char

  • MOUSE_LEFT (default)

  • 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.press() 命令时,Arduino 会接管您的鼠标!在使用该命令之前,请确保您有控制权。切换鼠标控制状态的按钮是有效的。

相关用法


注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 Mouse.press()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。