public void Run() { bool finished = false; do { Console.WriteLine("Input a char"); string response = Console.ReadLine(); char responseChar = (response == "") ? ' ' : char.ToUpper(response[0]); switch (responseChar) { case 'X': finished = true; break; default: // 得到按键信息的参数 KeyEventArgs keyEventArgs = new KeyEventArgs(responseChar); // 触发事件 KeyDown(this, keyEventArgs); break; } } while (!finished); }
private void OnKeyDown(object sender, KeyEventArgs e) { // 真正的事件处理函数 Console.WriteLine("Capture key: {0}", e.KeyChar); }