通过互联网发送鼠标位置

Sending mouse position over internet

本文关键字:鼠标 位置 互联网      更新时间:2023-10-16

如何从客户端 A 发送鼠标位置 =to=>SERVER=to=>客户端 B ?
下面的示例代码给我每 2 秒
一次位置输出有什么更好/更快的方法来做到这一点?
注意:使用 Winsock 和 cURL 会发出防病毒恶意软件警告
用法:用于远程控制

将鼠标位置从客户端 A 发送到服务器再到客户端 A 的当前 TEST 示例:

1.写入鼠标位置
2.store x,y 在发送.txt文件中
3.上传发送.txt作为临时.txt文件
到服务器4.删除接收.txt如果存在//错误 80 如果不存在
5.下载临时.txt作为接收.txt
6.读取接收.txt并在控制台中显示坐标

int x,y; //positions
LPCWSTR s=L"C://Documents and Settings//Administrator//Desktop//c++//FTP//send.txt";//location of file for sending
LPCWSTR r=L"C://Documents and Settings//Administrator//Desktop//c++//FTP//receve.txt";//location of received file
POINT cursor_pos;//for cursor position
HINTERNET hInternet;
    HINTERNET hFtpSession;
    hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    if (hInternet == NULL)
    {
        cout << "Error: " << GetLastError();
    }
    else
    {
        hFtpSession = InternetConnect(hInternet, L"www.test.net", INTERNET_DEFAULT_FTP_PORT, L"user", L"pass", INTERNET_SERVICE_FTP, 0, 0);
        if (hFtpSession == NULL)//not connect
        {
            cout << "Error: " << GetLastError();
        }
        else
        {    

            for(;;){
//file input
fstream inp;
inp.open(s);
GetCursorPos(&cursor_pos);
inp<<cursor_pos.x<<" "<<cursor_pos.y<<endl;//write curent position

inp.close();
           //UPLOADING
            if (!FtpPutFile(hFtpSession, s, L"//public_html//test//temp.txt", FTP_TRANSFER_TYPE_BINARY, 0))
            {
                cout << "ErrorPutFile: " << GetLastError();
                return 0;
            }

            remove("C://Documents and Settings//Administrator//Desktop//c++//FTP//receve.txt");//error 80 if file exist so remove it
           //DOWNLOADING
            if(!FtpGetFile(hFtpSession,L"//public_html//test//temp.txt",r,TRUE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY,0))
            {
            cout <<"ErrorGetFile"<<GetLastError();
            return 0;
            }//DELETING 
           if(!FtpDeleteFile(hFtpSession,L"//public_html//test//temp.txt")){
            cout <<"ErrorGetFile"<<GetLastError();
            return 0;
           }

ifstream outp(r);
while(outp>>x>>y){
cout<<"X: "<<x<<" "<<"Y:"<<y<<endl;//read coordinates
}
outp.close();
            }

        }
    }
return 0;

感谢您抽出宝贵时间:)

你可能会考虑SignalR,它非常适合这些事情。有关示例,请参阅 https://pepitosolis.wordpress.com/2013/12/08/signalr-2-0-persistent-connection-another-example-tracking-your-mouse-pointer/