getButton static method

int getButton(
  1. dynamic event
)

Implementation

static int getButton(event) {
  if (event.kind == PointerDeviceKind.touch && event is PointerDownEvent) {
    return 0;
  } else {
    final leftButtonPressed = event.buttons & 1 > 0;
    final rightButtonPressed = event.buttons & 2 > 0;
    final middleButtonPressed = event.buttons & 4 > 0;

    // Left button takes precedence over other
    if (leftButtonPressed) return 0;
    // 2nd priority is the right button
    if (rightButtonPressed) return 2;
    // Lastly the middle button
    if (middleButtonPressed) return 1;

    // Other buttons pressed? Just return the default (left)
    return 0;
  }
}