---
name: "mouse_x"
section: "3alleg"
platform: "linux"
package: "liballegro-doc"
version: "2:4.2.2-2.2"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/mouse_x"
---

# mouse\_x(3alleg)

Global variable with the mouse position/button state. Allegro game programming library.

## NAME

mouse\_x, mouse\_y, mouse\_z, mouse\_w, mouse\_b, mouse\_pos - Global variable with the mouse position/button state. Allegro game programming library.

## SYNOPSIS

**#include \<allegro.h\>**

**extern volatile int mouse\_x;**

**extern volatile int mouse\_y;**

**extern volatile int mouse\_z;**

**extern volatile int mouse\_w;**

**extern volatile int mouse\_b;**

**extern volatile int mouse\_pos;**

## DESCRIPTION

Global variables containing the current mouse position and button state.  Wherever possible these values will be updated asynchronously, but if  mouse\_needs\_poll() returns TRUE, you must manually call poll\_mouse() to  update them with the current input state. The \`mouse\_x' and \`mouse\_y'  positions are integers ranging from zero to the bottom right corner of  the screen. The \`mouse\_z' and \`mouse\_w' variables hold the current vertical and horizontal wheel position, when using an input driver that supports wheel mice. The \`mouse\_b' variable is a bitfield indicating the state of each button: bit 0 is the left button,  bit 1 the right, and bit 2 the middle button. Additional non standard mouse buttons might be available as higher bits in this variable. Usage example:

```
   if (mouse_b & 1)
      printf("Left button is pressed\n");
   if (!(mouse_b & 2))
      printf("Right button is not pressed\n");
```

The \`mouse\_pos' variable has the current X coordinate in the upper 16 bits and  the Y in the lower 16 bits. This may be useful in tight polling loops  where a mouse interrupt could occur between your reading of the two separate variables, since you can copy this value into a local variable with a single instruction and then split it up at your leisure. Example:

```
   int pos, x, y;
   pos = mouse_pos;
   x = pos >> 16;
   y = pos & 0x0000ffff;
```

## SEE ALSO

[**install\_mouse**(3alleg)](/install_mouse/3alleg.md), [**poll\_mouse**(3alleg)](/poll_mouse/3alleg.md), [**mouse\_needs\_poll**(3alleg)](/mouse_needs_poll/3alleg.md), [**exalpha**(3alleg)](/exalpha/3alleg.md), [**exlights**(3alleg)](/exlights/3alleg.md), [**exmouse**(3alleg)](/exmouse/3alleg.md), [**exshade**(3alleg)](/exshade/3alleg.md), [**exspline**(3alleg)](/exspline/3alleg.md), [**extrans**(3alleg)](/extrans/3alleg.md)
