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.