I have an application that lives in the tray, and I need to detect the user activity so that I can perform certain tasks. For windows, I know that I can use GetAsyncKeyState or SetWindowsHookEx, but I would like to have a cross-platform solution.
Does anyone have a solution for this? maybe a reimplementation of keyPressEvent? Or would it be easier to just setup some macros and do it separately?
This is inherently platform specific.
I’d make sure to isolate whatever you do and separate the mechanism of capturing the event and recording the keystrokes from the consumption of those keystrokes. That way you only have to implement the capture/record mechanism on each platform and all of the other code should be pretty portable.
You may want to take a look at what SDL has done here. http://www.libsdl.org/
They have managed to abstract off all of that sort of thing, not just keyboards.