Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Debouncing a mouse click?

This thread is locked; no one can reply to it. rss feed Print
Debouncing a mouse click?
nshade
Member #4,372
February 2004

Man I feel like I'm posting in here every day. I guess if I come in with code and at least try I feel like I'm not bothering you all.

Given this psudocode:

#SelectExpand
1bool debounce = false; 2while (1) 3{ 4 if (state.buttons & 1) 5 { 6 // Primary (e.g. left) mouse button is held. 7 printf("Mouse position: (%d, %d)\n", state.x, state.y); 8 //Hold debounce = true here so it only iterates once? 9 } 10 11 if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) 12 { 13 //release debounce = false so it can trigger again? 14 } 15}

The program will spit out X and Y position for as long as the mouse is down... How Would one "one shot" this so that only one position is captured until the button is lifted.

I think my logic is faulty. I tired a few iterations of this and it didn't seem to work...

EDIT

never mind, my brain is dumb - This is what I'm looking for

#SelectExpand
1al_get_mouse_state(&state); 2if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) 3{ 4 printf("Mouse position: (%d, %d)\n", state.x, state.y); 5}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: