getKeystate()之后的清除控制台输入
在按“ 1”之后,我有一个用于创建用户名的控制台登录系统。但是,每当我按该键时,按下的键都会显示在控制台输入中。我想摆脱这一点。
#include <Windows.h>
bool pressed1;
std::string inputUsername;
do
{
pressed1 = GetKeyState('1') & 0x8000;
if (pressed1) {
std::cout << "\nPressed '1' enter username: ";
std::cin >> inputUsername;
}
} while (!pressed1);
因此,执行和按下“ 1”控制台时说:
Pressed '1' enter username: 1
如何摆脱输入中的按下按钮?
I have a console login-system for creating a username after pressing '1'. But whenever i press that key, the pressed key shows up in the console input. I want to get rid of that.
#include <Windows.h>
bool pressed1;
std::string inputUsername;
do
{
pressed1 = GetKeyState('1') & 0x8000;
if (pressed1) {
std::cout << "\nPressed '1' enter username: ";
std::cin >> inputUsername;
}
} while (!pressed1);
So when executing and pressing '1' the console says:
Pressed '1' enter username: 1
How do i get rid of the pressed button in the input?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
flushConsoleInputBuffer(getStdhandle(std_input_handle))
另请参见以前的答案” 。
You can use
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE))
See also this previous answer.