如題,利用C語言的GetCursorPos函數實現. 示例:
#include <bits/stdc++.h> #include <windows.h> #include <conio.h> int main(){ long x, y; POINT pt = {0, 0}; LPPOINT xy = &pt; while(true){ // 獲取坐標 GetCursorPos(xy); // 打印坐標 printf("%d %d",pt.x,pt.y); Sleep(300); // 12個\b printf("\b\b\b\b\b\b\b\b\b\b\b\b"); // 12個空格 printf(" "); printf("\b\b\b\b\b\b\b\b\b\b\b\b"); //system("cls"); } }
這里使用了 退格-空格-退格 的方法代替system("cls") ,因為system每次調用時消耗的時間都較長.
background:#f9b289
過於簡單,歡迎CV