Event/signal when any kind of gui activity occurs
-
Just gonna start of explaining what I'm doing.
I have this desktop program that requires authentication from the user. User gets a login screen on startup and it is possible to switch to another user at runtime.
In the particular use case of this program, very frequently, two or more users will be using the program on the same computer and much of the data entered will be assigned to the currently logged in user.So the problem is that users will often forget tedious things like clicking the "switch user" button before doing something so I thought what if I just lock the program with a modal dialog login screen after it's been idle for a certain period of time.
That creates the sub problem of telling wheather the program is idle or not and also defining "what is idle?".
I guess it would be when no mouse or keyboard movement is going on inside the program's windows.So, works like a screensaver, but isolated to this program.
I did a quick search and seems Qt already has an event for when a window becomes active/inactive, so that should be trivial. But is there any easy(-ish) way to tell if any input is going on in the program's GUI?
Like maybe some global events that occur on mouse clicks, scrolls, key presses, etc?Then I could just keep a 'session active' timer which will be reset on every gui operation and then it proceeds to lock the program when a timeout is reached. (or something along those lines).
-
You could make a timer which triggers every 5 secs and checks whether the cursor has moved further than, for example, 2 pixels in that time (see QCursor::pos()). If it hasn't moved for n consecutive intervals, lock the application.
For the keyboard it's more difficult when your program doesn't have focus. I wouldn't recommend creating keyboard hooks for this, because your program wouldn't be distinguisable from a malicious keylogger.
If you just want to react to keyboard events while your application is active, look into event filters.//EDIT: Thought about it. If you're not writing a text editor or word processor, just checking the cursor position and ignoring the keyboard should be fine for your purpose.
//EDIT2: If this is an industrial application (i.e. doesn't need to be pretty but robust), assign each user his own background color tone. This way a user will feel foreign when working with a different account and should notice it right away.