如何检测 C++ 中是否按下了某个键?我想如何使用它的一个例子:
git merge
我发现有几篇文章说要使用 while (varOne == 0) {
if ('A' Key Pressing Code Detection Magic Goes Here) {
std::cout << "The 'A' key has been pressed.";
varOne = 2;
}
}
库,但是很多人建议不要使用它。我应该使用conio.h
吗?或者有其他方法吗? (不确定是否重要,但我在 Linux 上使用 VS Code。)
答案 0 :(得分:2)
由于您使用的是 linux,您可能想要寻找一个 curses
库。 ncurses
(现代 C++ curses
库)的可能有用信息:
https://www.linuxjournal.com/content/getting-started-ncurses,
https://invisible-island.net/ncurses/,
https://www.cyberciti.biz/faq/linux-install-ncurses-library-headers-on-debian-ubuntu-centos-fedora/。
我不是 linux
的真正专家,但这可能会有所帮助。
此处接受的答案:Where is the <conio.h> header file on Linux? Why can't I find <conio.h>? 解释了 conio.h
和 ncurses
。