如何对其它程序如IE,计算器等发送全局键盘和鼠标消息,重金购买(100分)

  • 主题发起人 主题发起人 wangzz
  • 开始时间 开始时间
W

wangzz

Unregistered / Unconfirmed
GUEST, unregistred user!
如果我想控制其他的运行的程序,就要向他们发送按键和鼠标的消息,如何做到,谢谢
 
用sendmessage
 
不会用,你写写一个例子吗,比如分别模拟鼠标和键盘在WINDOWS的计算器中<br>计算sin(6787*7798),谢谢
 
以前我钻研过,用打开进程边界的方法,不过没深里研究,觉得没什么用<br>你去看看那本&lt;Windows高级编程&gt;里面有的
 
<br>function fun_GetImageSize: TImageSize;<br>var<br>&nbsp; ISH: THandle;<br>&nbsp; CancelHandle: THandle;<br>&nbsp; WidthHandle : THandle;<br>&nbsp; HeightHandle: THandle;<br>&nbsp; TextW: array [0..255] of Char;<br>&nbsp; TextH: array [0..255] of Char;<br>begin<br>&nbsp; // Step 1: Call PS to show the 'Image Size' dialog.<br>&nbsp; prc_MenuClick(2,8,-1);<br>&nbsp; // Step 2: If success,get the two Edit's handles.<br>&nbsp; repeat<br>&nbsp; &nbsp; Application.ProcessMessages;<br>&nbsp; &nbsp; ISH:= FindWindow(PChar('PSFloatC'),PChar('Image Size'));<br>&nbsp; until &nbsp;ISH &lt;&gt; 0 ;<br><br>&nbsp; repeat<br>&nbsp; &nbsp; Application.ProcessMessages;<br>&nbsp; &nbsp; CancelHandle:= FindWindowEx(ISH,0,PChar('Button'),Pchar('Cancel'));<br>&nbsp; &nbsp; WidthHandle:= FindWindowEx(ISH,0,PChar('Edit'),nil);<br>&nbsp; &nbsp; HeightHandle:= FindWindowEx(ISH,WidthHandle,PChar('Edit'),nil);<br>&nbsp; Until ((CancelHandle&lt;&gt;0) and &nbsp;(WidthHandle&lt;&gt;0) and (HeightHandle&lt;&gt;0));<br><br>&nbsp; SendMessage(WidthHandle,WM_GETTEXT,Sizeof(TextW),LongInt(@TextW));<br>&nbsp; SendMessage(HeightHandle,WM_GETTEXT,Sizeof(TextH),LongInt(@TextH));<br>&nbsp; Form1.Caption:= TextW;<br>&nbsp; Result.X:= StrToInt(Form1.Caption);<br>&nbsp; Form1.Caption:= TextH;<br>&nbsp; Result.Y:= StrToInt(Form1.Caption);<br>&nbsp; form1.caption:= &nbsp;form1.caption+ ' &nbsp;_ &nbsp;'+TextW;<br>&nbsp; PostMessage(CancelHandle,BM_CLICK,0,0); //After Use, Close it.<br>end;<br><br><br><br>procedure prc_AdjustWindow(AWidth: Integer;AHeight: Integer);<br>var<br>&nbsp; PP: TPoint;<br>&nbsp; ISH:Thandle;<br>const offSetH=100;<br>const offSetW= 35;<br>begin<br><br>&nbsp; PP:=fun_GetImageSize;<br>&nbsp; if (PP.Y)/(PP.X) &gt; (AHeight/AWidth) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;Windows.SetWindowPos(PSH,Form1.Handle,Screen.Width-5,Screen.Height-5,Screen.Width-55,AHeight+offSetH,SWP_NOACTIVATE);<br>&nbsp; &nbsp;end;<br>&nbsp; if (PP.Y)/(PP.X) &lt; (AHeight/AWidth) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;Windows.SetWindowPos(PSH,Form1.Handle,Screen.Width-5,Screen.Height-5,AWidth+offSetW,Screen.Height-5,SWP_NOACTIVATE)<br>&nbsp; &nbsp;end;<br>&nbsp; repeat<br>&nbsp; Application.ProcessMessages;<br>&nbsp; ISH:= FindWindow(Pchar('PSFloatC'),PChar('Image Size'));<br><br>&nbsp; until &nbsp;ISH= 0 ;<br>&nbsp; SendMessage(PSH,<br>&nbsp; WM_COMMAND,<br>&nbsp; GetMenuItemID(GetSubMenu(GetMenu(PSH),6),7),0); //Click &nbsp;'VIew'-'Fit On Screen'<br>&nbsp; //prc_MenuClick(6,7,-1);<br>end;<br><br><br><br><br>procedure prc_MenuClick(m1,m2,m3: Integer);<br>begin<br>if m3 &gt;= 0 then<br>&nbsp; PostMessage(PSH,WM_COMMAND,<br>&nbsp; &nbsp; GetMenuItemID(GetSubMenu(GetSubMenu(GetMenu(PSH),m1),m2),m3)<br>&nbsp; &nbsp; &nbsp; ,0)<br>else<br>&nbsp; PostMessage(PSH,<br>&nbsp; WM_COMMAND,<br>&nbsp; GetMenuItemID(GetSubMenu(GetMenu(PSH),m1),m2),0);<br>end;<br><br><br><br><br>这是一个例子,看不懂给我发邮件:)
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部