detecting a full mouse click all at once

Ok, so I am trying to detect a mouse-click, and am stuck detecting both a mouse down and then a mouse up to constitute a 'click'. This can get tricky if you want to detect a full click as you would then have to detect the last VK lbutton pressed and then catch the very next VK button lmouse_up. Isn't there a VK code for a single click (both up and down)?

This is the sample code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
main()
{
bool shift = false;
bool clicked = false;

while(1)
{
cv::Point cursor = cvui::mouse();
				fetchCursorPosA(cursor, cur_x, cur_y, offset_x, offset_y);
				
				if (GetAsyncKeyState(VK_LBUTTON) < 0 && shift == false) { std::cout << "MOUSE BUTTON DOWN..................:" << std::endl; shift = true; lbutton_down = true; }
				if (GetAsyncKeyState(VK_LBUTTON) == 0 && shift == false) { std::cout << "MOUSE BUTTON UP..............................:" << std::endl; shift = true; lbutton_up = true; }
				if ((lbutton_down) && (lbutton_up)) { std::cout << "button clicked" << std::endl; clicked = true; std::cout << "CLICK" << std::endl; lbutton_down = false; lbutton_up = true; } //intial conditions

}

}

Last edited on
I do not know of a hardware side click detection event. You can do it to some controls, eg add a button click event handler to something (many, many non-button things can be wired to have a button click event, or they could in MFC).
I'll have do it the hard way. Thanks - : )
This module works:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
if (GetAsyncKeyState(VK_LBUTTON)<0)
					{
						cout << "left button pressed" << endl;
						pressed = TRUE;
						
						while (pressed) {
							if (GetAsyncKeyState(VK_LBUTTON) == 0)
							{
								cout << "left button NOT pressed" << endl;
								pressed = false;
								ctr++;
								std::cout << "click event: " << ctr << std::endl;
							
								
							}
								
						
					}
Last edited on
Topic archived. No new replies allowed.