如何在一个特定的程序中发送特定的键!(200分)(200分)

  • 主题发起人 主题发起人 baby_god
  • 开始时间 开始时间
B

baby_god

Unregistered / Unconfirmed
GUEST, unregistred user!
如果大家玩过UO的话,肯定知道UOLOOP的作用.<br>小弟不懂..请教各位..<br>
 
UO是什么东东?
 
模拟h键(发出按下h键的效果)<br>keybd_event($48,0,0,0); <br>keybd_event($48,0,KEYEVENTF_KEYUP,0);
 
对付网络程序应该有更好的办法。
 
其实就是一个模拟按键了,给你看看 :<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,<br>&nbsp; Forms, Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormKeyPress(Sender: TObject; var Key: Char);<br>&nbsp; private<br>&nbsp; &nbsp; AppInst: THandle;<br>&nbsp; &nbsp; AppWind: THandle;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>uses ShellAPI;<br>&nbsp;<br><br>procedure SendShift(H: HWnd; Down: Boolean);<br>var vKey, ScanCode, wParam: Word;<br>&nbsp; &nbsp; lParam: longint;<br>begin<br>&nbsp; vKey:= $10;<br>&nbsp; ScanCode:= MapVirtualKey(vKey, 0);<br>&nbsp; wParam:= vKey or ScanCode shl 8;<br>&nbsp; lParam:= longint(ScanCode) shl 16 or 1;<br>&nbsp; if not(Down) then lParam:= lParam or $C0000000;<br>&nbsp; SendMessage(H, WM_KEYDOWN, vKey, lParam);<br>end;<br><br>procedure SendCtrl(H: HWnd; Down: Boolean);<br>var vKey, ScanCode, wParam: Word;<br>&nbsp; &nbsp; lParam: longint;<br>begin<br>&nbsp; vKey:= $11;<br>&nbsp; ScanCode:= MapVirtualKey(vKey, 0);<br>&nbsp; wParam:= vKey or ScanCode shl 8;<br>&nbsp; lParam:= longint(ScanCode) shl 16 or 1;<br>&nbsp; if not(Down) then lParam:= lParam or $C0000000;<br>&nbsp; SendMessage(H, WM_KEYDOWN, vKey, lParam);<br>end;<br><br>procedure SendKey(H: Hwnd; Key: char);<br>var vKey, ScanCode, wParam: Word;<br>&nbsp; &nbsp; lParam, ConvKey: longint;<br>&nbsp; &nbsp; Shift, Ctrl: boolean;<br>begin<br>&nbsp; ConvKey:= OemKeyScan(ord(Key));<br>&nbsp; Shift:= (ConvKey and $00020000) &lt;&gt; 0;<br>&nbsp; Ctrl:= (ConvKey and $00040000) &lt;&gt; 0;<br>&nbsp; ScanCode:= ConvKey and $000000FF or $FF00;<br>&nbsp; vKey:= ord(Key);<br>&nbsp; wParam:= vKey;<br>&nbsp; lParam:= longint(ScanCode) shl 16 or 1;<br>&nbsp; if Shift then SendShift(H, true);<br>&nbsp; if Ctrl then SendCtrl(H, true);<br>&nbsp; SendMessage(H, WM_KEYDOWN, vKey, lParam);<br>&nbsp; SendMessage(H, WM_CHAR, vKey, lParam);<br>&nbsp; lParam:= lParam or $C0000000;<br>&nbsp; SendMessage(H, WM_KEYUP, vKey, lParam);<br>&nbsp; if Shift then SendShift(H, false);<br>&nbsp; if Ctrl then SendCtrl(H, false);<br>end;<br><br>function EnumFunc(Handle: HWnd; TF: TForm1): Bool; Far;<br>begin<br>&nbsp; TF.AppWind:= 0;<br>&nbsp; if GetWindowWord(Handle, GWW_HINSTANCE) = TF.AppInst then<br>&nbsp; &nbsp; TF.AppWind:= Handle;<br>&nbsp; result:= (TF.AppWind = 0);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var Text: Array[0..255] of char;<br>begin<br>&nbsp; AppInst:= ShellExecute(Handle, 'open', 'notepad.exe', nil, '', SW_NORMAL);<br>&nbsp; EnumWindows(@EnumFunc, longint(self));<br>&nbsp; AppWind:= GetWindow(AppWind, GW_CHILD);<br>end;<br><br>&nbsp;<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; SendKey(AppWind, 'T');<br>&nbsp; SendKey(AppWind, 'e');<br>&nbsp; SendKey(AppWind, 's');<br>&nbsp; SendKey(AppWind, 't');<br>end;<br><br>procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);<br>begin<br>&nbsp; if AppWind &lt;&gt; 0 then SendKey(AppWind, Key);<br>end;<br><br>end.<br>
 
接受答案了.
 
后退
顶部