Mouse.press()
描述
送出按下鼠标键的命令给电脑(相当于按着鼠标按键不放)。若要放开鼠标按键,请呼叫 Mouse.release() 函式。
在呼叫 Mouse.press()
函式之前,要先呼叫 Mouse.begin() 函式。
Mouse.press()
预设是鼠标左键。
注意:当你呼叫 Mouse.press()
函式后,86Duino 会接管你的鼠标,使它做出按下鼠标按键的行为(使用此函式前,请确认实体鼠标运作是没问题的)。 建议你可以在程式中,判断一个外接按钮是否按下,来决定是否送出按下 86Duino 鼠标按键的命令。
语法
Mouse.press();
Mouse.press(button);
参数
button
:要按下哪一个按键 char 型别
-MOUSE_LEFT
(预设)
-MOUSE_RIGHT
-MOUSE_MIDDLE
回传
无回传值
范例
void setup(){ // 按下这个开关相当于按下鼠标按键 pinMode(2,INPUT); // 按下这个开关相当于放开鼠标按键 pinMode(3,INPUT); // 初始化 HID 鼠标函式库 Mouse.begin(); } void loop(){ // 假如开关被按下了,就按下鼠标左键不放 if(digitalRead(2) == HIGH){ Mouse.press(); } // 假如开关被按下了,就放开鼠标左键 if(digitalRead(3) == HIGH){ Mouse.release(); } }
See also
- Mouse.begin()
- Mouse.click()
- Mouse.end()
- Mouse.move()
- Mouse.release()
- Mouse.isPressed()
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.