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.