I need to define keystrokes in the console project (not typing in the console)

How can this be implemented?

I will explain the task and my project in more detail I am not doing a big console game and for controlling the character I need to get data about the keystrokes as the picture is displayed in the console and the console is constantly cleaned and the data cannot be drawn into it again and for this I need some other way get keystroke data.

Closed due to the fact that the issue is too general for participants Denis , Ruslan_K , Denis Bubnov , Yuri , Vadizar 13 Mar '17 at 13:39 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • List and describe in more detail the events that you need to catch. - Artem Ionash

3 answers 3

Want to make a keylogger? Ayayay According to the pope for this need to beat.

But in general, the answer is the following: you need to use WinApi for this and catch the events of the operating system itself. This article will help: http://www.dreamincode.net/forums/topic/180436-global-hotkeys/

But it will be easier to use other people's work. For example, this project does exactly what you need using more than a simple syntax: https://github.com/fabriciorissetto/KeystrokeAPI . It will not take long.

  • now would keyloggers do on with # in 2017 - ParanoidPanda

The most trivial way to determine keystrokes for the case when your application is not a background one and is active:

public class Program { public static void Main() { ConsoleKeyInfo key; do { key = Console.ReadKey(); Console.WriteLine(key.Key + " клавиша была нажата"); } while (key.Key != ConsoleKey.Escape); // по нажатию на Escape завершаем цикл } } 

If you need a keystroke tracking method when the application is not active and is a background process, then we need to import the user32.dll helper library user32.dll :

 [DllImport("user32.dll")] public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc); [DllImport("user32.dll")] public static extern bool UnregisterHotKey(IntPtr hWnd, int id); 

There is a good answer regarding this option: Capture a keyboard keypress in the background . In principle, if you use the search, then the answers can be found. Or here's a ready, good and complete answer: Background Key Press Listener

    https://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C

    Here it can help, at least from here I took the code to track the movement of the mouse pointer outside the application form.