#include"graphics.h"
#include"windows.h"
int arr[2] = { 0,0};
int main()
{
char x;
initgraph(1080, 500);
setbkcolor(WHITE);
cleardevice();
setlinecolor(BLACK);
setfillcolor(BROWN);
while (1)
{
cleardevice();
fillcircle(arr[0], arr[1], 20);
if (GetAsyncKeyState(VK_DOWN))
arr[1] += 5;
if (GetAsyncKeyState(VK_UP))
arr[1] -= 5;
if (GetAsyncKeyState(VK_LEFT))
arr[0] -= 5;
if (GetAsyncKeyState(VK_RIGHT))
arr[0] += 5;
FlushMouseMsgBuffer();
}
}
目标:想通过GetAsyncKeyState来判断上下左右键以控制绘图小球在窗口的移动;问题:程序运行后,随便按下一个方向键,并立马松开,预期小球只移动一次,但是我这个程序不知为何 按下方向键后 小球直接跑远了