C# 键盘操作

2025-02-21 17:31:28
推荐回答(3个)
回答1:

只说说思路。
应该是去实现系统的事件,检测到系统(和你当前界面中)按 KEY_UP KEY_DOWN 类似的键盘的事件中,然后调用你对应此处的button的click事件的函数,就可以实现你要的效果了。

回答2:

每个按钮都去侦听键盘按下的动作,获取按下的字符是什么,不同的按钮针对需要做出的反应的字符做反应,代码我就不找了,你自己网上搜搜,很简单。

回答3:

public static void Main(String[] args){ bool tag = true; do { ConsoleKeyInfo info = Console.ReadKey(); switch (info.Key) { case ConsoleKey.E: Console.WriteLine("exit"); tag = false; break; case ConsoleKey.UpArrow: Console.WriteLine("Up"); break; case ConsoleKey.DownArrow: Console.WriteLine("Down"); break; case ConsoleKey.LeftArrow: Console.WriteLine("Left"); break; case ConsoleKey.RightArrow: Console.WriteLine("Right"); break; default: Console.WriteLine(info.Key); break; } } while (tag); Console.Read();}