Question Put the pressed key to a char without forms

Status
Not open for further replies.

MikeyJY

Member
Joined
Sep 19, 2021
Messages
11
Programming Experience
5-10
I want to get the pressed key to a char, without importing System.Windows.Forms. It is not a forms app, just a console app. Preferable with an event:
C#:
using System;
using System.Collections;
public class Program{
    List<char> Keys = new List<char>();
    //hypothetical
    public override void AnyKeyPressed(System.Windows.Input Key key){
        Keys.Add(key.ToChar());
    }
    public static void main(string[] args){
        for(int i = 0;i<Keys.Count();i++){
            Console.Write(Keys.ElementAt(i) + " ");
        }
    }
  
}
 
Last edited:
You would call Console.ReadKey to get the console input character by character. That method returns a ConsoleKeyInfo value, which has a KeyChar property, much like the e.KeyChar property in a WinForms KeyPress event handler.
 
You would call Console.ReadKey to get the console input character by character. That method returns a ConsoleKeyInfo value, which has a KeyChar property, much like the e.KeyChar property in a WinForms KeyPress event handler.
If my program will not have console at all, just a windows process?
 
It's not for us to teach you how to make a keylogger. While a legitimate use for such software is not impossible, malicious uses would be far more common. Thread closed.
 
Status
Not open for further replies.
Back
Top Bottom