放置一个button,设置form.keypreview=true;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,math;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormKeyPress(Sender: TObject;
var Key: Char);
procedure Button1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure FormKeyUp(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure FormDblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Step:integer=4;
do
wn:boolean=false;
implementation
{$R *.DFM}
procedure TForm1.FormKeyPress(Sender: TObject;
var Key: Char);
var mousepos:tpoint;
begin
case key of
'*': SetCursorPos(trunc(screen.Width/2),trunc(screen.height/2));
'a','A':
{left}
begin
GetCursorPos(mousepos);
SetCursorPos(max(mousepos.x-step,0),mousepos.y);
end;
'd','D':
{Right}
begin
GetCursorPos(mousepos);
SetCursorPos(min(screen.Width,mousepos.x+step),mousepos.y);
end;
's','S':
{Down}
begin
GetCursorPos(mousepos);
SetCursorPos(mousepos.x,min(screen.width,mousepos.y+step));
end;
'w','W':
{Up}
begin
GetCursorPos(mousepos);
SetCursorPos(mousepos.x,max(0,mousepos.y-step));
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if (key=ord('o'))or(key=ord('O')) then
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
end;
procedure TForm1.FormKeyUp(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if (key=ord('o'))or(key=ord('O')) then
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
end;
procedure TForm1.FormDblClick(Sender: TObject);
begin
ShowMessage('this isdo
ubleclick');
end;
end.