Is there a way I could track my mouse movement outside the widget?
-
I want to create an app which would track mouse movement outside the widget. For example: when the cursor is moving outside of the widget scope, I will be a able to detect cursor movement. I know how to set the tracking when the cursor is over the widget (EventFilter || MouseMoveEvent).
-
You could take a look at QObject::installEventFilter or QCoreApplication::installNativeEventFilter
If even the latter does not provide events that are outside our widget, the you would probably have to use system-native code instead of Qt.
One trick might be to have a fullscreen transparent widget overlaying the whole screen.
-
@Asperamanca I have used the EventFilter but it only track mouse activity over the widget, if it's outside the widget then it does not work. I have used WinApi functions:
Opened it in another thread. The idleTicks variable will go to zero if movement detected if no movement it will increment itself.LASTINPUTINFO lii;
memset(&lii, 0, sizeof(lii));
lii.cbSize = sizeof(lii);
while (1){
GetLastInputInfo(&lii);
long currTicks = GetTickCount();
long lastInputTicks = lii.dwTime;
long idleTicks = currTicks - lastInputTicks;
}