Mouse.isPressed()
描述
检查鼠标上的按键有没有被按下。
语法
Mouse.isPressed();
Mouse.isPressed(button);
参数
当没有输入参数,预设是左键。
button
:要检查哪一个按键 char 型别
-MOUSE_LEFT
(预设)
-MOUSE_RIGHT
-MOUSE_MIDDLE
回传
布林值:指定的键有没有被按下
范例
void setup(){ // 按下这个开关相当于按下鼠标按键 pinMode(2,INPUT); // 按下这个开关相当于放开鼠标按键 pinMode(3,INPUT); // 初始化串列通讯 Serial1.begin(9600); // 初始化 HID 鼠标函式库 Mouse.begin(); } void loop(){ // 用来检查鼠标状态的变数 int mouseState=0; // 假如开关被按下了,就按下鼠标左键不放,并且记录目前状态 if(digitalRead(2) == HIGH){ Mouse.press(); mouseState=Mouse.isPressed(); } // 假如开关被按下了,就放开鼠标左键,并且记录目前状态 if(digitalRead(3) == HIGH){ Mouse.release(); mouseState=Mouse.isPressed(); } // 印出鼠标按键的状态 Serial1.println(mouseState); delay(10); }
See also
- Mouse.begin()
- Mouse.click()
- Mouse.end()
- Mouse.move()
- Mouse.press()
- Mouse.release()
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.