 // =================================================================================
 // Volatile variables
 // =================================================================================
-volatile ENCODER_ xAxis;
-volatile ENCODER_ yAxis;
-volatile boolean leftButton   = false;
-volatile boolean middleButton = false;
-volatile boolean rightButton  = false;
+volatile ENCODER_ xAxis = {0, 0};
+volatile ENCODER_ yAxis = {0, 0};
+
+// =================================================================================
+// Global variables
+// =================================================================================
+BUTTON_ leftButton   = {false, false, MOUSE_LEFT,   0b1000, 0};
+BUTTON_ middleButton = {false, false, MOUSE_MIDDLE, 0b0010, 0};
+BUTTON_ rightButton  = {false, false, MOUSE_RIGHT,  0b0100, 0};
 
 // =================================================================================
 // Setup function

/* ================================================================================
   Author  : GuilleAcoustic
   Date    : 2015-05-22
   Revision: V1.0
   Purpose : Opto-mechanical trackball firmware
   --------------------------------------------------------------------------------
   Wiring informations: Sparkfun Pro micro (Atmega32u4)

     - Grey   : Switch 1                     |   Pin: PB3
     - White  : Switch 2                     |   Pin: PB2
     - Black  : Switch 3                     |   Pin: PB1
   --------------------------------------------------------------------------------
   Latest additions:
     - 2016-01-28: Software switch debouncing
   ================================================================================ */

// =================================================================================
// Type definition
// =================================================================================

#ifndef DEBOUNCE_THREASHOLD
#define DEBOUNCE_THREASHOLD 50
#endif

// =================================================================================
// Type definition
// =================================================================================
typedef struct ENCODER_
{
  int8_t  coordinate;
  uint8_t index;
} ENCODER_;

typedef struct BUTTON_
{
  boolean state;
  boolean needUpdate;
  char    button;
  byte    bitmask;
  long    lastDebounceTime;
} BUTTON_;

// =================================================================================
// Constant definition
