我尝试跟踪是否按下了BUTTON1
BUTTON2
和BUTTON3
。
问题是在OSX ctrl + click
上被视为右键单击。
因此,如果我有以下内容(使用处理程序):
boolean mouse_left_pressed;
boolean mouse_right_pressed;
void setup() {
size(200, 100);
}
void draw() {
background(0);
fill(255);
text("left: "+mouse_left_pressed, 50, 50);
text("right: "+mouse_right_pressed, 50, 75);
}
public void mousePressed(MouseEvent e) {
if (e.getButton() == LEFT) mouse_left_pressed = true;
if (e.getButton() == RIGHT) mouse_right_pressed = true;
}
public void mouseReleased(MouseEvent e) {
if (e.getButton() == LEFT) mouse_left_pressed = false;
if (e.getButton() == RIGHT) mouse_right_pressed = false;
}
如果我执行以下步骤:
然后,尽管我再也没有按下鼠标,但是mouse_left_pressed
的状态仍然为真。
有没有办法获得释放的实际鼠标按钮?
答案 0 :(得分:0)
这是因为OSX中的Control +左键单击等效于右键单击。有点hack,但是您可以按如下方式检查修饰符:
boolean mouse_left_pressed;
boolean mouse_right_pressed;
void setup() {
size(200, 100);
}
void draw() {
background(0);
fill(255);
text("left: "+mouse_left_pressed, 50, 50);
text("right: "+mouse_right_pressed, 50, 75);
}
public void mousePressed(MouseEvent e) {
if (e.getButton() == LEFT) mouse_left_pressed = true;
if (e.getButton() == RIGHT) {
if (!e.isControlDown()) {
mouse_right_pressed = true;
}
else {
mouse_left_pressed = true;
}
}
}
public void mouseReleased(MouseEvent e) {
println(e);
if (e.getButton() == LEFT) mouse_left_pressed = false;
if (e.getButton() == RIGHT) {
if (!e.isControlDown()) {
mouse_right_pressed = false;
}
else {
mouse_left_pressed = false;
}
}
}