See if a key was presssed
-
Hi, I have a problem. I need to "watch" to keyboard, to see, if whatever key was pressed globally, not just in the app, but globally.
Is this possible? I have this, but it only picks up keys like shift, alt, caps lock, f keys, but not letters or numbers:void MainWindow::keyPressEvent(QKeyEvent *event) //included in .h file under the private category { if (event->KeyPress) { qDebug() << "key"; } }
-
@Sucharek said in See if a key was presssed:
I have this, but it only picks up...
if (event->KeyPress) {
Who knows, since I don't see any such
QKeyEvent
member variable?not just in the app, but globally.
Is this possible?
I hope not! You want to monitor the keyboard no matter which application has focus? Isn't that how keystroke stealers work? :) Maybe it's possible, but I would have thought it would be down to the windowing system having some native way of doing it? Like Windows has e.g. How to use System-Wide Hotkeys in your Qt application, but that's for like some special key combination registered with the OS, not what you are asking for.
-
Hi @JonB, never thought about the keystore thing :o
I'm making a screen on time program and I'm counting active and passive time. For the passive time, I need to detect mouse movement and the keyboard. I guess I'll need to stick with the mouse.
Thanks for the help. -
@Sucharek said in See if a key was presssed:
a screen on time program
I'm afraid I don't know what that is?
active and passive time
Active & passive time in your app, or overall usage of PC by user?
Anything to do with another program, or even a different window in your own app, is not going to be
MainWindow::
anything. -
@Sucharek
I'm getting confused. I think you need to be very specific about what key presses you are looking for, or have to look for:- Those to one window in your app?
- Those to any window in your app?
- Those to completely separate windows belonging to other applications?
-
@Sucharek
Then like I said I do not think Qt offers anything for that, and I do not know if the Windows OS/windowing system even allows it from a normal program (e.g. not the device driver, and excluding specialist software like "keyloggers"). -
Hi, for listening to keystrokes regardless of which program or window they end up in, there are a couple of Win32 API:s you can use from a normal (unprivileged) program, for example: SetWindowsHookExW()
-
@hskoglund said in See if a key was presssed:
you can use from a normal (unprivileged) program, for example: SetWindowsHookExW()
Wow! So without any warning or elevated privilege, any Windows program I install could be logging all keystrokes I make in any application? Nice.
-
Yes, it's been around since Windows 3.0, there's an older forum discussion here
I posted an example program there, see if I can get the link to gitlab working again... -
@hskoglund
Indeed! There is a blow-by-blow discussion in https://0x00sec.org/t/windows-keylogging-part-i/99Scary how easy Windows makes it!
-
As I remember it, those API:s were initially designed for training/teaching how to use a computer (not for spying on you!) for example the acronym CBT you'll see in the docs stands for Computer Base Training :-)
-
@hskoglund the root to hell is paved with good intentions....
but this is also the reason, why anti-cheat software from games has to be so terrible invasive on the Operating System.
-
Hi all, thanks for your replies, but I think I'm gonna have to stick with only the mouse movement. If I get this right, it won't work on Linux, so that's a bad thing.
Edit: Messing with Windows APIs is something I have no idea how to do and it would take days for me to learn it. The mouse is probably the only way.
Thanks again for your answers. -
@Sucharek
I never knew why you needed to track key presses to other applications. And I hope Linux doesn't allow it anyway! :)I don't know whether it helps, but you can (I believe) track focus changes/activate/deactivate windows in your app. Which I think would accompany going typing keys into another application. Maybe you could investigate those?