I'm developing a small app that will show an alert whenever I haven't pressed any key or clicked any mouse button for a while, just for helping me focus. But, I can't find a way to get buttons pressed outside my application frame.
My app is been developed in C for ubuntu 18.04 using gnome as desktop environment. I've thought if there was any way it would work, it would be by using X11 library methods, so I've tried using them but had no success. The method XNextEvent only captures events when my application is focused.
I don't really need to know what was the key or mouse button pressed, it isn't a keylogger. All I'm interested is if there was an event from mouse or keyboard.
show an alert whenever I haven't pressed any key or clicked any mouse button for a while
This is very similar to what a screensaver would do, and most efficient way of implementing it will be to use the X11 Screen Saver Extension. The XScreenSaverQueryInfo
function will populate a structure which includes the number of milliseconds since the last user input (saver_info.idle
).