1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| Unit Unit1;
Interface
Uses Windows, SysUtils, Classes, Graphics, Controls,
Forms, ExtCtrls, StdCtrls;
Type
TForm1 = Class(TForm)
Timer1: TTimer;
Procedure Timer1Timer(Sender: TObject);
End;
Var
Form1: TForm1;
{----------------------------------------------------------------}
{ }Implementation{ }
{----------------------------------------------------------------}
{$R *.DFM}
Var
Pos: TPoint;
Etatkb: Array[1..255] Of Boolean;
{----------------------------------------------------------------}
Procedure TForm1.Timer1Timer(Sender: TObject);
Var
x: Integer;
Begin
Timer1.Interval := 1;
For x := Low(Etatkb) To High(Etatkb) Do
If ((GetAsyncKeyState(x) And 32768) <> 0) Then Etatkb[x] := True
Else If ((GetAsyncKeyState(x) And 32768) = 0) Then Etatkb[x] := False;
Pos := Mouse.CursorPos;
{ Exemple 1 : Déplacement du curseur avec les touches de directions }
If (Etatkb[VK_LEFT]) Then Dec(Pos.x, 2);
If (Etatkb[VK_RIGHT]) Then Inc(Pos.x, 2);
If (Etatkb[VK_UP]) Then Dec(Pos.y, 2);
If (Etatkb[VK_DOWN]) Then Inc(Pos.y, 2);
If (Etatkb[VK_LEFT]) Or (Etatkb[VK_RIGHT]) Or
(Etatkb[VK_UP]) Or (Etatkb[VK_DOWN]) Then SetCursorPos(Pos.x, Pos.y);
{ Exemple 2 : Touche Echap pour quitter le programme }
If (Etatkb[VK_ESCAPE]) Then Close;
End;
{----------------------------------------------------------------}
End. |