关于模拟鼠标点击(控制其它程序),并非MOUSE_EVEN...谢谢大家 ( 积分: 5 )

  • 主题发起人 主题发起人 laohe
  • 开始时间 开始时间
L

laohe

Unregistered / Unconfirmed
GUEST, unregistred user!
以前使用下面这种,可以达到效果.但用来操作其它程序时,鼠标就跑过去了.
getcursorpos(point);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
setcursorpos(point.x,point.y);

所以请教一下,有没有后台式操作的.获取使用SendMessage发送信息之类的,让他在按程序的Handle来发送指令,让鼠标移到所指坐标,然后点击
 
以前使用下面这种,可以达到效果.但用来操作其它程序时,鼠标就跑过去了.
getcursorpos(point);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
setcursorpos(point.x,point.y);

所以请教一下,有没有后台式操作的.获取使用SendMessage发送信息之类的,让他在按程序的Handle来发送指令,让鼠标移到所指坐标,然后点击
 
我这里有给别的程序窗体上的控件发送文本的代码。。
改改就可以了

SendMessage(handle,bm_click,1,1);

代码如下:
unit usendtxt;

interface

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

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function GetEditHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;
var
buffer: array[0..255] of Char;
buffer1: array[0..255] of Char;
begin
Result := True;
//得到目标窗口的控件
GetClassName(hwnd,buffer,256);
GetWindowText(hwnd,buffer1,100);
//找到发消息的目标窗口的目标控件
if (StrPas(Buffer)='Edit') and (strpas(buffer1)='woool.9966.org') then
begin
GetWindowText(hwnd,buffer1,100);
PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)
Result:=False; //终止循环
end;
end;//end of function

function GetEditHandle1(hwnd: Integer; lparam: Longint):Boolean; stdcall;
var
buffer: array[0..255] of Char;
buffer1: array[0..255] of Char;
begin
Result := True;
//得到目标窗口的控件
GetClassName(hwnd,buffer,256);
GetWindowText(hwnd,buffer1,100);
//找到发消息的目标窗口的目标控件
if (StrPas(Buffer)='Edit') and (strpas(buffer1)='D:/Program Files/Shanda/Woool/') then
begin
GetWindowText(hwnd,buffer1,100);
PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)
Result:=False; //终止循环
end;
end;//end of function

procedure TForm1.FormCreate(Sender: TObject);
begin
winexec('新路传奇世界.exe',1);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var i, WinampHandle,tmpHandle,tmpHandle1:integer;
s,s1,s2:string;
begin
s := '79109710.vicp.net';
s1 := 'e:/woool/';
s2 := '新路传奇世界登录器';
WinampHandle:=FindWindow( nil,'传私登陆V2.5免费版');

if WinampHandle = 0 then
ShowMessage('Winamp 没有运行')
else
SendMessage(WinampHandle, wm_SetText, 0, integer(pchar(s2)));
tmpHandle:=WinampHandle;
tmpHandle1:= WinampHandle ;
EnumChildWindows(tmpHandle,@GeteditHandle,Integer(@tmpHandle));

// SetForegroundWindow(WinampHandle);
// PostMessage(WinampHandle,WM_QUIT,0,0);
SendMessage(tmpHandle, wm_SetText, 0, integer(pchar(s)));

EnumChildWindows(tmpHandle1,@GeteditHandle1,Integer(@tmpHandle1));

// SetForegroundWindow(WinampHandle);
// PostMessage(WinampHandle,WM_QUIT,0,0);
SendMessage(tmpHandle1, wm_SetText, 0, integer(pchar(s1)));

application.Terminate;
// keybd_event(VK_LWIN, MapVirtualKey(VK_LWIN, 0), 0, 0);
// keybd_event(VK_LWIN, MapVirtualKey(VK_LWIN, 0), KEYEVENTF_KEYUP, 0);
//C暂停,X播放,V停止,B下一首,Z上一首,(必须为大写),详见Winamp帮助
// SendMessage(WinampHandle, WM_KEYDOWN, ord('1'), 0);

// SendMessage(WinampHandle, WM_KEYDOWN, VK_LEFT, 0); //后退5秒
// SendMessage(WinampHandle, WM_KEYDOWN, VK_RIGHT, 0); //前进5秒
end;

end.

第一次答问题。。有错误请别见笑
 
接受答案了.
 

Similar threads

I
回复
0
查看
605
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部