Урок на Делфи Перехват нажатия клавиатуры и мыши


задание на delphi. Перехват нажатия клавиш. (заготовка для шпиона)

unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.ComCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Timer1: TTimer;
Button1: TButton;
Button2: TButton;
procedure Timer1Timer(Sender: TObject);
procedure ListBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ListBox1.Clear;
end;
procedure TForm1.ListBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and (Key=49) then
ListBox1.Items.Add('nagata klava Ctrl+1');
if (ssShift in Shift) and (Key=50) then
ListBox1.Items.Add('nagata klava Shift+2');
if (ssAlt in Shift) and (Key=51) then
ListBox1.Items.Add('nagata klava Alt+3');
if Key = VK_RIGHT then
begin
ListBox1.Items.Add('nagata klava vpravo');
end;
if Key = VK_LEFT then
begin
ListBox1.Items.Add('nagata klava vlevo');
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if GetAsyncKeyState(VK_LBUTTON) <> 0 then
ListBox1.Items.Add('nagata levaia knopka mishi');
if GetAsyncKeyState(VK_RBUTTON) <> 0 then
ListBox1.Items.Add('nagata pravia knopka mishi');
if GetAsyncKeyState(VK_F2) <> 0 then
ListBox1.Items.Add('nagata f2');
if GetAsyncKeyState(ord(56)) <> 0 then
ListBox1.Items.Add('nagata 8');
if GetAsyncKeyState(ord(57)) <> 0 then
ListBox1.Items.Add('nagata 9');
end;
end.



Скачать