I want to use the MOUSEEVENTF_ABSOLUTE and MOUSEEVENTF_MOVE functions in C++, but I am not quite sure how to. What is the difference between them and how can I use a combination of those actions and MOUSEEVENTF_LEFTDOWN and MOUSEEVENTF_LEFTUP to click on certain coordinates?
Thank you in advance.
If you can, please show it in context.How do I control mouse movement in c++?
What library do those functions come from? They are not standard C++, they belong to some library you are using.
Anyways, here are some clues based on what I assume they are doing.
These appear to be events, to be caught in an event loop:
while ( more_events )
{
switch (event)
{
case MOUSEEVENTF_ABSOLUTE: // code code break;
case MOUSEEVENTF_MOVE: // code code break;
}
}
Something like that. Here's what I think those particular events mean:
MOUSEEVENTF_ABSOLUTE is probably telling you the x and y coordiantes of the mouse cursor. If it gives you (10, 0) that probably means the cursor is 10 pixels to the right of the origin (probably window center).
MOUSEEVENTF_MOVE is probably telling you the distance the mouse has changed since it's last position. If the x value you get is -3, that probably means the mouse has moved 3 pixels to the left from where it was before.
MOUSEEVENTF_LEFTDOWN and UP probably are telling you when the user presses and releases the left mouse button.
Here's code to draw lines when the user drags:
int old_x, old_y, new_x, new_y;
case MOUSEEVENTF_LEFTDOWN:
held = true; break;
case MOUSEEVENTF_LEFTUP:
held = false; break;
case MOUSEEVENTF_ABSOLUTE: // gives you an x, y
old_x = new_x; old_y = new_y; new_x = x; new_y = y; break;
case MOUSEEVENTF_MOVE: // gives you a dx, dy
if ( held )
{
draw_line( // from old_x, old_y to new_x, new_y );
}
That's the best I can do without knowing what library you're in. Consult the library's documentation for more details on the functions.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment