#include <bits/stdc++.h> #include <windows.h> #include <conio.h>//控制台输入输出头文件 using namespace std; int main(){ HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE); //HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);//获取标准输出的句柄 COORD coord={0,0};//保存光标坐标 HANDLE handle1=GetStdHandle(STD_OUTPUT_HANDLE); COORD coord1={1,1}; SetConsoleCursorPosition(handle,coord); cout<<"HH"; SetConsoleCursorPosition(handle1,coord1); cout<<"AA"; while(1){ if(kbhit()){ int key=getch(); if(key==72 || key==75 || key==77 || key==80){ SetConsoleCursorPosition(handle,coord); cout<<" "; switch(key){ case 72: coord.Y--;break; case 75: coord.X--;break; case 77: coord.X++;break; case 80: coord.Y++;break; default: break; } SetConsoleCursorPosition(handle,coord); cout<<"HH"; }else if(key==119 || key==97 || key==100 || key==115){ SetConsoleCursorPosition(handle1,coord1); cout<<" "; switch(key){ case 119: coord1.Y--;break; case 97: coord1.X--;break; case 100: coord1.X++;break; case 115: coord1.Y++;break; default: break; } SetConsoleCursorPosition(handle1,coord1); cout<<"AA"; } } } return 0; }
标签:STD,handle,GetStdHandle,输入输出,OUTPUT,HANDLE,控制台,include From: https://www.cnblogs.com/fushuxuan/p/18132980