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.