Z
zhengxq
Unregistered / Unconfirmed
GUEST, unregistred user!
服务端:
使用抓屏程序进行抓屏然后传送到客户端,并显示在客户端窗体的Image上,然后用鼠标在客户端的Image上进行操作,再将鼠标操作和位置作为参数传回服务端。代码省略。
客户端:
使用如下代码,将客户端传来的鼠标操作和位置参量进行模拟客户端的远程控制操作。
procedure TForm1.Image1DblClick(Sender: TObject);
begin
clientsocket1.Socket.SendText(inttostr(cx)+'ssdouble'+inttostr(cy));
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
cx:=x;
cy:=y;
if shift=[ssleft] then
begin
clientsocket1.Socket.SendText(inttostr(x)+'ssleft'+inttostr);
end;
if shift=[ssright] then
begin
clientsocket1.Socket.SendText(inttostr(x)+'ssright'+inttostr);
end;
end;
cx,cy是两个自定义变量.
服务器端:
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
s:string;
s2char;
sx,sy:integer
begin
s:=socket.ReceiveText;
s2:=pchar(s);
if strpos(s2,'ssdouble')<>nil then
begin
sx:=strtoint(copy(s,1,strpos(s2,'ssdouble')-s2));
sy:=strtoint(copy(s,(strpos(s2,'ssdouble')-s2)+9,length(s)-(strpos(s2,'ssdouble')-s2)-8));
setcursorpos(sx,sy);
mouse_event(MOUSEEVENTF_LEFTDOWN, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTDOWN, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, sx, sy, 0, 0 );
end;
if strpos(s2,'ssleft')<>nil then
begin
sx:=strtoint(copy(s,1,strpos(s2,'ssleft')-s2));
sy:=strtoint(copy(s,(strpos(s2,'ssleft')-s2)+7,length(s)-(strpos(s2,'ssdouble')-s2)-6));
setcursorpos(sx,sy);
mouse_event(MOUSEEVENTF_LEFTDOWN, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, sx, sy, 0, 0 );
end;
if strpos(s2,'ssright')<>nil then
begin
sx:=strtoint(copy(s,1,strpos(s2,'ssright')-s2));
sy:=strtoint(copy(s,(strpos(s2,'ssright')-s2)+8,length(s)-(strpos(s2,'ssright')-s2)-7));
setcursorpos(sx,sy);
mouse_event(MOUSEEVENTF_RIGHTDOWN, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_RIGHTUP, sx, sy, 0, 0 );
end;
end;
现在的问题是,在服务端的模拟鼠标操作中,可能是由于分辨率的问题,导致鼠标的位置不对(错位),如17寸和15寸显示器/800*600和1024*768,请问有什么办法解决这个问题?
使用抓屏程序进行抓屏然后传送到客户端,并显示在客户端窗体的Image上,然后用鼠标在客户端的Image上进行操作,再将鼠标操作和位置作为参数传回服务端。代码省略。
客户端:
使用如下代码,将客户端传来的鼠标操作和位置参量进行模拟客户端的远程控制操作。
procedure TForm1.Image1DblClick(Sender: TObject);
begin
clientsocket1.Socket.SendText(inttostr(cx)+'ssdouble'+inttostr(cy));
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
cx:=x;
cy:=y;
if shift=[ssleft] then
begin
clientsocket1.Socket.SendText(inttostr(x)+'ssleft'+inttostr);
end;
if shift=[ssright] then
begin
clientsocket1.Socket.SendText(inttostr(x)+'ssright'+inttostr);
end;
end;
cx,cy是两个自定义变量.
服务器端:
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
s:string;
s2char;
sx,sy:integer
begin
s:=socket.ReceiveText;
s2:=pchar(s);
if strpos(s2,'ssdouble')<>nil then
begin
sx:=strtoint(copy(s,1,strpos(s2,'ssdouble')-s2));
sy:=strtoint(copy(s,(strpos(s2,'ssdouble')-s2)+9,length(s)-(strpos(s2,'ssdouble')-s2)-8));
setcursorpos(sx,sy);
mouse_event(MOUSEEVENTF_LEFTDOWN, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTDOWN, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, sx, sy, 0, 0 );
end;
if strpos(s2,'ssleft')<>nil then
begin
sx:=strtoint(copy(s,1,strpos(s2,'ssleft')-s2));
sy:=strtoint(copy(s,(strpos(s2,'ssleft')-s2)+7,length(s)-(strpos(s2,'ssdouble')-s2)-6));
setcursorpos(sx,sy);
mouse_event(MOUSEEVENTF_LEFTDOWN, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, sx, sy, 0, 0 );
end;
if strpos(s2,'ssright')<>nil then
begin
sx:=strtoint(copy(s,1,strpos(s2,'ssright')-s2));
sy:=strtoint(copy(s,(strpos(s2,'ssright')-s2)+8,length(s)-(strpos(s2,'ssright')-s2)-7));
setcursorpos(sx,sy);
mouse_event(MOUSEEVENTF_RIGHTDOWN, sx, sy, 0, 0 );
mouse_event(MOUSEEVENTF_RIGHTUP, sx, sy, 0, 0 );
end;
end;
现在的问题是,在服务端的模拟鼠标操作中,可能是由于分辨率的问题,导致鼠标的位置不对(错位),如17寸和15寸显示器/800*600和1024*768,请问有什么办法解决这个问题?