我要用delphi 写一个模拟按键,不过现在能循环点击了,但不能停下来,我用钩子也行啊,,有没有高人看看这
unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hook:HHOOK;
function keyhook(ncode:Integer;waparam:WPARAM;lparam:LPARAM):LRESULT;stdcall
implementation
{$R *.dfm}
var
falg:Boolean;
function keyhook(ncode:Integer;waparam:WPARAM;lparam:LPARAM): LRESULT;
begin
if waparam=65 then
begin
falg:=True;
ShowMessage('a');
end;
Result:=CallNextHookEx(hook,nCode,waParam,lParam) ;
end;
function myfun :Integer;
begin
while falg=False do
begin
Mouse.CursorPos:=Point(530,530);
mouse_event(MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_LEFTUP,0,0,0,0);
Sleep(3000);
ShowMessage('fsa');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
hook:=SetWindowsHookEx(WH_KEYBOARD,@keyhook,0,getcurrentthreadid);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnhookWindowsHookEx(hook);
end;
procedure TForm1.btn1Click(Sender: TObject);
var
id:THandle;
begin
CreateThread(nil, 0, @MyFun, nil, 0, ID);
end;
end. 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hook:HHOOK;
function keyhook(ncode:Integer;waparam:WPARAM;lparam:LPARAM):LRESULT;stdcall
implementation
{$R *.dfm}
var
falg:Boolean;
function keyhook(ncode:Integer;waparam:WPARAM;lparam:LPARAM): LRESULT;
begin
if waparam=65 then
begin
falg:=True;
ShowMessage('a');
end;
Result:=CallNextHookEx(hook,nCode,waParam,lParam) ;
end;
function myfun :Integer;
begin
while falg=False do
begin
Mouse.CursorPos:=Point(530,530);
mouse_event(MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_LEFTUP,0,0,0,0);
Sleep(3000);
ShowMessage('fsa');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
hook:=SetWindowsHookEx(WH_KEYBOARD,@keyhook,0,getcurrentthreadid);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnhookWindowsHookEx(hook);
end;
procedure TForm1.btn1Click(Sender: TObject);
var
id:THandle;
begin
CreateThread(nil, 0, @MyFun, nil, 0, ID);
end;
end. 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询