當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing mouseButton用法及代碼示例

Processing, mouseButton用法介紹。

說明

當按下鼠標按鈕時,係統變量 mouseButton 的值將設置為 LEFTRIGHTCENTER ,具體取決於按下的按鈕。 (如果沒有按下按鈕,mouseButton 可能會重置為 0 。因此,最好先使用 mousePressed 測試是否有任何按鈕被按下,然後再測試 mouseButton 的值,如上例所示。)

例子

// Click within the image and press
// the left and right mouse buttons to 
// change the value of the rectangle
void draw() {
  if (mousePressed && (mouseButton == LEFT)) {
    fill(0);
  } else if (mousePressed && (mouseButton == RIGHT)) {
    fill(255);
  } else {
    fill(126);
  }
  rect(25, 25, 50, 50);
}
// Click within the image and press
// the left and right mouse buttons to 
// change the value of the rectangle
void draw() {
  rect(25, 25, 50, 50);
}

void mousePressed() {
  if (mouseButton == LEFT) {
    fill(0);
  } else if (mouseButton == RIGHT) {
    fill(255);
  } else {
    fill(126);
  }
}

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 mouseButton。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。