Problems with the mouse
arthur arthur

Hello,
first excuse my english, i'm french.

i'll try to explain my problem simply : i want to detect a mouse left click (easy), but detect just a "click" (which means mouse left button down, then released).

i've tried that :

if (mouse_b & 1)
         printf("Left button is pressed\n");

but the printf is but until the left button is released.

does anybody got an answer for me please ?

thx for all !

Niunio

Try this:

int Clicked = 0;

...
if (!Clicked && (mouse_b & 1))
         printf("Left button is pressed\n");
Clicked = mouse_b & 1;

Tobias Dammers

Hackish solution:

if (mouse_b & 1) {
  printf("Left mouse button pressed\n");
  while (mouse_b & 1)
    poll_mouse(); // not strictly necessary, but can't hurt either
}

Note that this locks your application until the mouse button is released, so a more sophisticated approach would be:

// global var:
int last_mouse_b = 0;
int cur_mouse_b = 0;

// then in main loop:
last_mouse_b = cur_mouse_b;
cur_mouse_b = mouse_b;
if ((cur_mouse_b & 1) && !(last_mouse_b & 1))
  printf("Left mouse button\n");

Thread #585859. Printed from Allegro.cc