请大家帮我看看这个远控问题。200分(200分)

  • 主题发起人 主题发起人 yy0692
  • 开始时间 开始时间
Y

yy0692

Unregistered / Unconfirmed
GUEST, unregistred user!
为什么我在远控的时候鼠标不能同步移动呢?但我看别人做的远程制桌面程序都能同步啊,我做这个的原理是,先得到主控机的鼠标位置,然后发送到被控机,最后由被控机执行鼠标移动(是在局域网中实现控制的,千兆网)
这是主控端的代码,用了鼠标和键盘勾子的控件MouseHook, KeyboardHook
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, XPMan, StdCtrls, shellapi, ComCtrls, TrayIcon, ScktComp, Menus,
ExtCtrls, MouseHook, KeyboardHook, inifiles;

type
TForm1 = class(TForm)
XPManifest1: TXPManifest;
Edit1: TEdit;
Label1: TLabel;
StatusBar1: TStatusBar;
Button1: TButton;
ClientSocket1: TClientSocket;
KeyboardHook1: TKeyboardHook;
MouseHook1: TMouseHook;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure MouseHook1MouseMove(const Handle: HWND; const X, Y: Integer);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

end;

var
Form1: TForm1;

implementation
var
myinifile:TInifile;
{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);
begin
if (edit1.Text='') or (edit2.Text='') then
begin
MessageBox(Handle, 'IP地址和端口号必须填写!', '提示', MB_OK);
end
else
begin
if Button1.Caption='连接' then

begin

Button1.Caption:='断开';

ClientSocket1.Address:=Edit1.Text;

ClientSocket1.Active:=False;

ClientSocket1.Active:=True;

Edit1.Enabled:=false;

Edit2.Enabled:=false;

end else

begin

Button1.Caption:='连接';

ClientSocket1.Active:=False;

Edit1.Enabled:=true;

Edit2.Enabled:=true;

end;

end;

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if ClientSocket1.Active then

ClientSocket1.Active:=False;
mousehook1.Stop;
end;

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var

info:string;

begin

info:=ClientSocket1.Socket.ReceiveText;//接收信息

end;


procedure TForm1.FormCreate(Sender: TObject);
var
filename:string;
begin
filename:=ExtractFilePath(paramstr(0))+'config.ini';
myinifile:=TInifile.Create(filename);

mousehook1.Start
end;

procedure TForm1.MouseHook1MouseMove(const Handle: HWND; const X,
Y: Integer);
begin
statusbar1.Panels[1].Text :=Format('X:%d:Y:%d', [X, Y]);
ClientSocket1.Socket.SendText(Format('%d!%d$', [X, Y]));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
form1.Close ;
end;

end.
_________________________________________________________________
这是被控端的代码
unit server;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls, ExtCtrls, XPMan;

type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
Memo1: TMemo;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Bevel1: TBevel;
Button1: TButton;
XPManifest1: TXPManifest;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ServerSocket1Listen(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure UpdateState;//更新当前的连接信息
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
function mx(FName: String): String;
var
x: Integer;
begin
x := Pos('!', FName);
if x > 0 then Result := Copy(FName, 1, x - 1)
else Result := FName;
end;

function my(FNamea: String): String;
var
g: Integer;
t: Integer;
begin
g := Pos('$', FNamea);
t:=pos('!' , FNamea);
if g > 0 then Result := Copy(FNamea, t + 1 , g-t-1)
else Result := FNamea;
end;


procedure TForm1.UpdateState;
begin
Label1.Caption:='已有 '+IntToStr(ServerSocket1.Socket.ActiveConnections)+' 台计算机连接...';
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
ServerSocket1.Active:=False;

ServerSocket1.Active:=True;

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if ServerSocket1.Active then

ServerSocket1.Active:=False;

end;

procedure TForm1.ServerSocket1Listen(Sender: TObject;
Socket: TCustomWinSocket);
begin
UpdateState;
end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
UpdateState;
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
UpdateState;
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var info,mouseinfoX,mouseinfoY:string;
begin
info:=Socket.ReceiveText;
mouseinfoX:=mx(info);
mouseinfoY:=my(info);
SetCursorPos(strtoint(mouseinfox),strtoint(mouseinfoy));
Memo1.Lines.Add(mouseinfox+mouseinfoy);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
form1.Close;
end;

end.
 
发份源码给我。包括第三方控件。我帮你调试一下。

Email: xzh65414@hotmail.com
 
我已经发了,请帮我看看
 
lz
可以发一份给我吗?我也很感兴趣,我想可能是在传输的流量上出了问题
我的email:andd_chen@126.com
 
后退
顶部