问题
I want to write my own keylogger using Java. To write the keylogger i would need a hook file that will catch the keyevents by the users. How can i write this hook file so that i am able to get the keys user presses. I am unaware how to write a global key listener in C.
回答1:
What you are trying to do will not be platform independent. As such, I can only give you a hint on how to do it on windows.
In windows, the way to do this is by using the winapi. You can use the SetWindowsHookEx function with the WH_KEYBOARD
argument which:
Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
This way, you will basically tell windows to call your predefined function (sent as argument to SetWindowsHookEx) every time a key is pressed. You can read about specifics on the webpage I gave you.
Since the SetWindowsHookEx function is windows specific, note that you cannot use this on linux or any other os. Also, for a basic program to do what you want, you don't really need Java. You can pretty much do everything in C/C++.
来源:https://stackoverflow.com/questions/10684594/writing-a-key-listener-in-c