

These are then passed to the function for processing. Whenever the user interacts with the mouse, while it is over the image being displayed: The mouse event type and event flags are recorded, along with the mouse x and y coordinates. The available list of events is documented here. As shown below, we create the logic to draw a rectangle, based on certain mouse events.
USING C TO GET MOUSE COORDINATES HOW TO
Let’s understand how to associate this function with specific mouse events. You need not specify any input arguments to the function, these will be populated automatically when the user interacts with the mouse. This works because we are going to register this function name to be associated with mouse events. In this case, we have named it drawRectangle(). You can however name the function whatever you like. Here, this particular function is associated with mouse events, so we define it as a MouseCallback function. Called only when certain user interface events are detected, this type of functions came to be known as the ‘Callback’ functions. Points to store the center of the circle and a point on the circumferenceīegin by defining a special ‘Callback’ function that will draw a rectangle on the image displayed in the named window. If c is pressed, clear the window, using the dummy image SetMouseCallback("Window", drawRectangle) highgui function called when mouse events occur Make a temporary image, which will be used to clear the image Rectangle(image, top_left_corner, bottom_right_corner, Scalar(0,255,0), 2, 8 ) When left mouse button is released, mark bottom right corner Mark the top left corner when left mouse button is pressed Void drawRectangle(int action, int x, int y, int flags, void *userdata) function which will be called on mouse input Point top_left_corner, bottom_right_corner Points to store the bounding box coordinates Using namespace to nullify use of cv::function() syntax # If c is pressed, clear the window, using the dummy image # highgui function called when mouse events occurĬv2.setMouseCallback("Window", drawRectangle) # Make a temporary image, will be useful to clear the drawing # When left mouse button is released, mark bottom right cornerĬv2.rectangle(image, top_left_corner, bottom_right_corner, (0,255,0),2, 8) # Mark the top left corner when left mouse button is pressed Global top_left_corner, bottom_right_corner # function which will be called on mouse inputĭef drawRectangle(action, x, y, flags, *userdata): # Lists to store the bounding box coordinates of the mouse relative ONLY to the GameScreen. takes the handler to the games screen and I can pass in &pt, and retrieve coords I am looking for a way to GetCursorPosition(GameScreen, &pt) or something that I see the function GetCursorPosition(&pt) but theres no tie in of this function HWND GameScreen = FindWindow(0,"Title of the game") HWND myapplication //this is usually just plain old hwnd or MY applictions handler but I cant find a function where I can tie in that handler in order to get the coords I need. So I grab the handler to the games window. E.g I just need coords of the games window to wherever the mouse is on that games window only!

When mouse is being moved in the games window whatever the coordinates are of the mouse in the games window is what I need. I cannot find any functions for doing this. The coordinates are to be retrieved and are needs to be relative to the games windows, and not the entire desktop\screen of windows\my computer. I am building my application to output the coordinates to my applications screen. One window is my program, the other is a games window.
USING C TO GET MOUSE COORDINATES WINDOWS
Ok I am doing some windows API programming that deals with two applications\windows.
