Release mouse control from namedwindow

I took over development work on an augmented reality game, currently running on windows 10, that has extensive use of OpenCV throughout; including vision (tracking) functions, image processing (blob detection and removal), and creation of the user interface via highgui. The game also allows for the usage of button-controllers to assist with play; the buttons are custom wired to a usb mouse, windows recognizes the button controllers as generic HIDs. A “control” namedwindow with trackbars was created to allow adjustment of game parameters during runtime; setmousecallback() was assigned to this control window. I will include segments of the code below; I am trying to release the mouse-control from the window while the game functions, so the cursor does not have to be located over the control window. Currently, the window must have mouse control with the cursor on a portion of the window, or the two button-controllers will not work. The windows api includes the ReleaseCapture() function, which appears to perform the task I am looking to implement. However, there appears to be no equivalent function in OpenCV. I am seeking advice about how to do this for the “control” namedwindow. My perception is the only way this can happen is to reprogram the button-controllers so they are seen as raw input devices, rather than a HID usb mouse.

The callback function simply returns the appropriate boolean value if a button-controller is pressed or released.

the UI code:

cv::Mat lmouse_img = imread(“mouse.png”);
namedWindow(“control”, WINDOW_NORMAL);
moveWindow(“control”, 1000, 0);
resizeWindow(“control”, 400, 1000);
imshow(“control”, lmouse_img);

setMouseCallback("control", CallBack_mouse, NULL); 

//parameter window
cv::createTrackbar("goalSize1", "control", &theField.goalSize_p1, 200);
cv::createTrackbar("goalSize2", "control", &theField.goalSize_p2, 200);

you’re asking for general winapi programming advice. don’t expect too much from this forum in that regard. it’s not a forum for winapi.

if you had a fullscreen window, the position of the cursor wouldn’t matter.

you need “game APIs”, not whatever that API is.

the complement of that API is SetCapture function (winuser.h) - Win32 apps | Microsoft Docs

you can’t get events that Windows won’t give you. the description of that windows API says that, if you had “gained control” (opposite of that API), even then you won’t get clicks if the cursor isn’t on your own windows. that’s regardless of what OpenCV can (can’t) do.

to clarify, you aren’t looking to release any control, you are looking to gain “control”, or information.

dig into OpenCV’s source code to find out if any of those apis are called there.

if there’s an issue of ordering the calls suitably, that means you need to reorder your callback setter calls.