Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
540 B
1
Indexable
Never
var buttonMaster = new ButtonMaster();

buttonMaster.ButtonPressed += (sender, eventArgs)
    => Console.WriteLine($"pressed  ---> {eventArgs.Key}");

while (true)
    buttonMaster.OnButtonPressed(Console.ReadKey(true).KeyChar);


public class ButtonMaster
{
    public event EventHandler<ButtonPressedEventArgs> ButtonPressed;

    public void OnButtonPressed(char key)
    {
        ButtonPressed?.Invoke(this, new ButtonPressedEventArgs() { Key = key });
    }
}

public class ButtonPressedEventArgs
{
    public char Key { get; set; }
}