L
lcl_003
Unregistered / Unconfirmed
GUEST, unregistred user!
我下载了remotecxp代码研究,发现控制其他电脑时鼠标左键的抬起发不过去,而按下可以。但是鼠标右键按下抬起都能发过去。代码看不出有啥区别啊:(哪位帮忙分析下是啥问题啊。
这是控制端的鼠标按下,抬起,移动的代码
procedure TRemoteCPCFm.FormMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if SpeedButton4.Down = False then exit; //如果鼠标标志置上则
if Form1.IdFTCPClient.Connected = False then exit; //如果网络开通则
try
Form1.IdFTCPClient.Write('鼠标命令' + EOL); //发送鼠标命令---1
StringsLen := 0;
SendStrings.Clear;
SendStrings.Append('鼠标移动'); //发送鼠标参数---2
SendStrings.Append('随便'); //数据对齐---3
//发送鼠标参数---4
SendStrings.Append(IntToStr((X * RemoteScreenWidth) div Screen.Width));
//发送鼠标参数---5
SendStrings.Append(IntToStr((Y * RemoteScreenHeight) div Screen.Height));
StringsLen := Length(SendStrings.Text);
Form1.IdFTCPClient.WriteInteger(StringsLen);
Form1.IdFTCPClient.WriteStrings(SendStrings);
sleep(10);
except
Panel2.Caption := '注意:鼠标命令失败!';
end;
end;
procedure TRemoteCPCFm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if SpeedButton3.Down = False then exit; //如果键盘标志置上则
if Form1.IdFTCPClient.Connected = False then exit; //如果网络开通则
try
Form1.IdFTCPClient.Write('键盘命令' + EOL); //发送键盘命令---1
StringsLen := 0;
SendStrings.Clear;
SendStrings.Append('键盘按下'); //发送键盘命令---2
SendStrings.Append(IntToStr(Key)); //发送键盘虚拟码参数---3
StringsLen := Length(SendStrings.Text);
Form1.IdFTCPClient.WriteInteger(StringsLen);
Form1.IdFTCPClient.WriteStrings(SendStrings);
except
Panel2.Caption := '注意:键盘命令失败!';
end;
end;
procedure TRemoteCPCFm.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if SpeedButton3.Down = False then exit; //如果键盘标志置上则
if Form1.IdFTCPClient.Connected = False then exit; //如果网络开通则
try
Form1.IdFTCPClient.Write('键盘命令' + EOL); //发送键盘命令---1
StringsLen := 0;
SendStrings.Clear;
SendStrings.Append('键盘抬起'); //发送键盘命令---2
SendStrings.Append(IntToStr(Key)); //发送键盘虚拟码参数---3
StringsLen := Length(SendStrings.Text);
Form1.IdFTCPClient.WriteInteger(StringsLen);
Form1.IdFTCPClient.WriteStrings(SendStrings);
except
Panel2.Caption := '注意:键盘命令失败!';
end;
end;
下面是被控端的代码
procedure RemoteMouseControl(AThread: TIdPeerThread);
var
MouseState: string; //按键状态
MouseButton: string; //鼠标之左-- 中-- 右键
MousePos: TPoint; //鼠标点
ReadStringLen: integer;
ReadStrings: TStringList;
begin
try
ReadStrings := TStringList.Create;
except
exit;
end;
try
ReadStringlen := AThread.Connection.ReadInteger;
if ReadStringLen > 200 then
begin
ReadStrings.Free;
exit;
end;
ReadStrings.Text := AThread.Connection.ReadString(ReadStringLen);
except
ReadStrings.Free;
exit;
end;
if ReadStrings.Count < 4 then exit;
MouseState := ReadStrings[0];
MouseButton := ReadStrings[1];
try
MousePos.X := StrToInt(ReadStrings[2]);
MousePos.Y := StrToInt(ReadStrings[3]);
except
ReadStrings.Free;
exit;
end;
ReadStrings.Free;
if MouseState = '鼠标按下' then //处理鼠标按下模拟
begin
if MouseButton = '左键' then
Mouse_Event(MOUSEEVENTF_LEFTDOWN, MousePos.X, MousePos.Y, 0, 0);
if MouseButton = '中键' then
Mouse_Event(MOUSEEVENTF_MIDDLEDOWN, MousePos.X, MousePos.Y, 0, 0);
if MouseButton = '右键' then
Mouse_Event(MOUSEEVENTF_RIGHTDOWN, MousePos.X, MousePos.Y, 0, 0);
end else
if MouseState = '鼠标抬起' then //处理鼠标抬起模拟
begin
if MouseButton = '左键' then
Mouse_Event(MOUSEEVENTF_LEFTUP, MousePos.X, MousePos.Y, 0, 0);
if MouseButton = '中键' then
Mouse_Event(MOUSEEVENTF_MIDDLEUP, MousePos.X, MousePos.Y, 0, 0);
if MouseButton = '右键' then
Mouse_Event(MOUSEEVENTF_RIGHTUP, MousePos.X, MousePos.Y, 0, 0);
end else
if MouseState = '鼠标移动' then //处理鼠标移动模拟
begin
SetCursorPos(MousePos.X, MousePos.Y);
end;
end;
这是控制端的鼠标按下,抬起,移动的代码
procedure TRemoteCPCFm.FormMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if SpeedButton4.Down = False then exit; //如果鼠标标志置上则
if Form1.IdFTCPClient.Connected = False then exit; //如果网络开通则
try
Form1.IdFTCPClient.Write('鼠标命令' + EOL); //发送鼠标命令---1
StringsLen := 0;
SendStrings.Clear;
SendStrings.Append('鼠标移动'); //发送鼠标参数---2
SendStrings.Append('随便'); //数据对齐---3
//发送鼠标参数---4
SendStrings.Append(IntToStr((X * RemoteScreenWidth) div Screen.Width));
//发送鼠标参数---5
SendStrings.Append(IntToStr((Y * RemoteScreenHeight) div Screen.Height));
StringsLen := Length(SendStrings.Text);
Form1.IdFTCPClient.WriteInteger(StringsLen);
Form1.IdFTCPClient.WriteStrings(SendStrings);
sleep(10);
except
Panel2.Caption := '注意:鼠标命令失败!';
end;
end;
procedure TRemoteCPCFm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if SpeedButton3.Down = False then exit; //如果键盘标志置上则
if Form1.IdFTCPClient.Connected = False then exit; //如果网络开通则
try
Form1.IdFTCPClient.Write('键盘命令' + EOL); //发送键盘命令---1
StringsLen := 0;
SendStrings.Clear;
SendStrings.Append('键盘按下'); //发送键盘命令---2
SendStrings.Append(IntToStr(Key)); //发送键盘虚拟码参数---3
StringsLen := Length(SendStrings.Text);
Form1.IdFTCPClient.WriteInteger(StringsLen);
Form1.IdFTCPClient.WriteStrings(SendStrings);
except
Panel2.Caption := '注意:键盘命令失败!';
end;
end;
procedure TRemoteCPCFm.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if SpeedButton3.Down = False then exit; //如果键盘标志置上则
if Form1.IdFTCPClient.Connected = False then exit; //如果网络开通则
try
Form1.IdFTCPClient.Write('键盘命令' + EOL); //发送键盘命令---1
StringsLen := 0;
SendStrings.Clear;
SendStrings.Append('键盘抬起'); //发送键盘命令---2
SendStrings.Append(IntToStr(Key)); //发送键盘虚拟码参数---3
StringsLen := Length(SendStrings.Text);
Form1.IdFTCPClient.WriteInteger(StringsLen);
Form1.IdFTCPClient.WriteStrings(SendStrings);
except
Panel2.Caption := '注意:键盘命令失败!';
end;
end;
下面是被控端的代码
procedure RemoteMouseControl(AThread: TIdPeerThread);
var
MouseState: string; //按键状态
MouseButton: string; //鼠标之左-- 中-- 右键
MousePos: TPoint; //鼠标点
ReadStringLen: integer;
ReadStrings: TStringList;
begin
try
ReadStrings := TStringList.Create;
except
exit;
end;
try
ReadStringlen := AThread.Connection.ReadInteger;
if ReadStringLen > 200 then
begin
ReadStrings.Free;
exit;
end;
ReadStrings.Text := AThread.Connection.ReadString(ReadStringLen);
except
ReadStrings.Free;
exit;
end;
if ReadStrings.Count < 4 then exit;
MouseState := ReadStrings[0];
MouseButton := ReadStrings[1];
try
MousePos.X := StrToInt(ReadStrings[2]);
MousePos.Y := StrToInt(ReadStrings[3]);
except
ReadStrings.Free;
exit;
end;
ReadStrings.Free;
if MouseState = '鼠标按下' then //处理鼠标按下模拟
begin
if MouseButton = '左键' then
Mouse_Event(MOUSEEVENTF_LEFTDOWN, MousePos.X, MousePos.Y, 0, 0);
if MouseButton = '中键' then
Mouse_Event(MOUSEEVENTF_MIDDLEDOWN, MousePos.X, MousePos.Y, 0, 0);
if MouseButton = '右键' then
Mouse_Event(MOUSEEVENTF_RIGHTDOWN, MousePos.X, MousePos.Y, 0, 0);
end else
if MouseState = '鼠标抬起' then //处理鼠标抬起模拟
begin
if MouseButton = '左键' then
Mouse_Event(MOUSEEVENTF_LEFTUP, MousePos.X, MousePos.Y, 0, 0);
if MouseButton = '中键' then
Mouse_Event(MOUSEEVENTF_MIDDLEUP, MousePos.X, MousePos.Y, 0, 0);
if MouseButton = '右键' then
Mouse_Event(MOUSEEVENTF_RIGHTUP, MousePos.X, MousePos.Y, 0, 0);
end else
if MouseState = '鼠标移动' then //处理鼠标移动模拟
begin
SetCursorPos(MousePos.X, MousePos.Y);
end;
end;