Arduino

Reference Language | Libraries | Comparison | Changes

Mouse

## Mouse.isPressed()

#### Description

Checks the current status of all mouse buttons, and reports if any are pressed or not.

#### Syntax

Mouse.isPressed();
Mouse.isPressed(button);

#### Parameters

When there is no value passed, it checks the status of the left mouse button.

button: which mouse button to check - char

- MOUSE_LEFT (default)
- MOUSE_RIGHT
- MOUSE_MIDDLE

#### Returns

boolean : reports wether a button is pressed or not

#### Example

void setup(){
//The switch that will initiate the Mouse press
pinMode(2,INPUT);
//The switch that will terminate the Mouse press
pinMode(3,INPUT);
//Start serial communication with the computer
Serial1.begin(9600);
//initiate the Mouse library
Mouse.begin();
}
void loop(){
//a variable for checking the button's state
int mouseState=0;
//if the switch attached to pin 2 is closed, press and hold the right mouse button and save the state ina variable
if(digitalRead(2) == HIGH){
Mouse.press();
mouseState=Mouse.isPressed();
}
//if the switch attached to pin 3 is closed, release the right mouse button and save the state in a variable
if(digitalRead(3) == HIGH){
Mouse.release();
mouseState=Mouse.isPressed();
}
//print out the current mouse button state
Serial1.println(mouseState);
delay(10);
}
[Get Code]

#### See also

- Mouse.begin()
- Mouse.click()
- Mouse.end()
- Mouse.move()
- Mouse.press()
- Mouse.release()

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

### Share

### This link has expired.
Please re-subscribe to our Newsletters.

### Subscribe to our Newsletters

Email

Please enter a valid email to subscribe

Arduino Newsletter
Arduino Store Newsletter

### Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy

###### Newsletter

- ©2015 Arduino
- Copyright Notice
- Contact us
- About us
- Careers