Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法在不使用 Windows 消息或 std::cin 流的情况下获得控制台中的最后一次按键?我听说标准库中有一个函数。解决方案最好尽可能便携。提前感谢您的帮助。
有conio.h但它不是技术标准。在 Linux 上,我的第一个 Google 搜索建议是termios.h。
不是很便携,但您甚至可以从 Windows 下的控制台应用程序使用 GetAsyncKeyState 访问当前键状态。更具技术性且同样特定于窗口的方法是使用 SetWindowsHookEx 将键盘挂接到系统中的回调中,该回调仅存储最后按下的键。
但是您的基本问题:控制台+可移植性-似乎暗示cin是您最好的选择-您需要cin不提供什么?
您是否考虑过使用像 pdcurses 这样的诅咒库?这是我所知道的唯一一个可以进行控制台管理的跨平台库。