Setting the Cursor Position in a Win32 Console Application

前端 未结 5 1421
走了就别回头了
走了就别回头了 2020-11-30 08:42

How can I set the cursor position in a Win32 Console application? Preferably, I would like to avoid making a handle and using the Windows Console Functions. (I spent all m

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 09:19

    #include 
    #include 
    using namespace std;
    int main(int argc, char *argv[])
    {
      int x,y;
      cin>>x>>y;
      SetCursorPos(x,y); //set your co-ordinate
      Sleep(500);
      mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0); // moving cursor leftdown
      mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0); // moving cursor leftup //for accessing your required co-ordinate
      system("pause");
      return EXIT_SUCCESS;
    }
    

提交回复
热议问题