win11,vs2022
无法通过键盘控制小球移动
#include<iostream>
#include<graphics.h>
#include<conio.h>
#include<thread>
#include<chrono>
using namespace std;
int x=50, y=50;
void drawball()
{
setfillcolor(RED);
solidcircle(x, y, 20);
}
int main()
{
initgraph(1000, 600, SHOWCONSOLE);
setbkcolor(WHITE);
cleardevice();
while (true)
{
cleardevice();
drawball();
int key = _getch();
if (_kbhit())
{
switch (key)
{
case'w':
case'W':
y -= 5;
break;
case'a':
case'A':
x -= 5;
break;
case's':
case'S':
y += 5;
break;
case'd':
case'D':
x += 5;
break;
}
}
}
closegraph();
return 0;
}