Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to record keys pressed?

Tags:

c#

console

Essentially I want to record every key press (including keydown/keyup and mouse clicks) and when they occurred so that I can create a macro out of them.

I found a ton of stuff about key presses and WinForms or WPF, but I don't really need a GUI, I just want to dump it out to the console after I'm done processing it.

So how can I record all key presses, even when my console window doesn't have focus?


Sample output:

Send {q down}
Sleep 98
Send {q up}
Sleep 4
Send {f down}
Sleep 102
Send {f up}
Sleep 43
Send {a down}
Sleep 26
Send {s down}
Sleep 111
Send {a up}
Sleep 18
Send {s up}
Sleep 17
Send {a down}
Sleep 62
Send {space down}
Sleep 72
Send {a up}
Sleep 5
Send {space up}

Using WPF for now, but the input text field has to be focused. I'd rather be able to record the keystrokes while I'm in my game, hence the question :)

like image 490
mpen Avatar asked Jul 21 '11 02:07

mpen


People also ask

How do I track my key presses?

The Windows on-screen keyboard is a program included in Windows that shows an on-screen keyboard to test modifier keys and other special keys. For example, when pressing the Alt , Ctrl , or Shift key, the On-Screen Keyboard highlights the keys as pressed.

How do I record keyboard input?

Record keyboard input Hotkey are a combination of the SHIFT / CTRL / ALT / WIN key(s) with an additional letter and are recognized by Macro Recorder as such. They will be saved in the automation file as a hotkey and output in the same way when the macro is being executed.

How do I find the keyboard history on my computer?

On your device In Windows 10, select Start , then select Settings > Privacy > Activity history. In Windows 11, select Start , then select Settings > Privacy & security > Activity history.

How are keystrokes recorded on a computer?

At the BIOS level, the firmware records the keystrokes after they reach the computer. At the keyboard device level, the keystrokes are recorded before they even reach the computer. Some of these devices can even be built into the keyboard, making it difficult to find or detect.

How to record mouse and keyboard on PC?

After downloading and installing the program on your PC, a screen will open with all the software functions. To start recording mouse and keyboard just click on RECORD and then you can proceed. At any time you can stop recording (even using the key ESC) and then save the macro on your PC.

What is an auto keyboard Presser?

An auto keyboard presser is a software which is used mainly when a combination of single key has to be pressed many times. It can easily emulate the several key combinations like the Spacebar, Enter Key, Arrow Keys, Backspace and the Function Keys.

Why is my keyboard not recording all my keystrokes?

Your keyboard is not set up to automatically record keystrokes. Someone must install keylogging hardware or software on your computer to record keystrokes. Keylogging hardware may take the form of either firmware run at the BIOS level or a device connected between a computer's keyboard and the computer itself.


Video Answer


2 Answers

Have a look at the SetWindowsHookEx function. This can be used to monitor keystrokes across the system.

like image 186
Paul Alexander Avatar answered Oct 19 '22 04:10

Paul Alexander


As far as I know, in order to accomplish this you will need to hook into Win32 API.

This project may help you get started.

like image 24
Tom Studee Avatar answered Oct 19 '22 04:10

Tom Studee