0

I have a Windows Form (C#) with a button on it. I'm trying to make it so when I click on the button it will wait for a key to be pressed by the user. Then save whatever key they pressed to a var.

My research led me to ReadKey() which is almost what I need, but not for the console. I can't find any simple solution for this.

        private void Point1_Click(object sender, EventArgs e) {
            Point1.Text = "Press key...";
            //Wait for any keyboard key to be pressed.
            //Save user input to:
            string userInput;
            Point1.Text = "Success!";
        }
  • Subscribe to [`KeyDown`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.keydown?view=net-5.0) event. – 大陸北方網友 Jan 22 '21 at 02:51
  • Is this what you mean? https://stackoverflow.com/questions/9418199/what-is-the-best-way-to-implement-a-shortcut-editor-textbox – Jeremy Lakeman Jan 22 '21 at 03:16
  • I tried subscribing to KeyDown events but I can't get it to work within my existing button click. And @JeremyLakeman that might be what I need but there's not any explanation so I'm struggling to get a working example from that in my project. – Parallel Pancakes Jan 22 '21 at 03:48

0 Answers0