app in background read keys pressed by user
i want to do a application which works in background and read all keys pressed by user and save it in file. i start to write it开发者_JAVA百科 in Win forms and use keys Pressed event but it works when form is focused:/
It is another way to do it? i hear about Windows Service, but i never use it :/
You can do it with help of these:
- DirectX look into MDX
- KeyLogger Application for C#
- Creating a simple keylogger in C#
I don't know your reasons, but I just hope they are "good".
After doing a lot of research looking for a good code to use to achieve this, I've decided to create my own C# Keylogger API. It's very simple and clean:
api.CreateKeyboardHook((character) => { Console.Write(character); });
You just need to pass a callback and the API will return the key pressed by the user, among other things like: the screen the user was in that moment. Obviously, it works in background.
More details here: https://github.com/fabriciorissetto/KeystrokeAPI
I'm assuming you want to intercept all key events to all windows:
I wouldn't recommend C# for this. You'll need to drop to the Win32/64 API, which can be done, but you'd be better off using Visual C++ / something without training wheels.
There are several ways to do this. The easiest, by far, is to register a hook for keyboard events. Implement a basic service and handle the key-press events in your main loop / event handler. You can also just brute-force the keyboard state in a tight polling loop, but this will make the CPU cry.
There's 1,000,001 ways to install your own keyboard driver without admin privileges, but you're going to need to find one yourself, assuming you go down that road.
I seriously doubt that anyone on stackoverflow will help you create a key logger. You're going to need to dive into the bowels of the Win32 API and, likely, figure it out yourself. It isn't difficult if you have a solid C background. Windows "security" is little more than smoke & mirrors.
精彩评论