
20.07.2025, 11:47
|
Прохожий
|
|
Регистрация: 11.06.2014
Сообщения: 37
Версия Delphi: RAD Studio XE3
Репутация: 10
|
|
Error: Error in type definition
Здравствуйте. Почему при компиляции Lazarus выдает ошибку unit1.pas(36,16) Error: Error in type definition
и указывает на строку hHook: HHOOK = 0;
? Два дня понять не могу, что ему не нравится.
Код:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, Windows;
type
{ TForm1 } TForm1 = class(TForm)
ClickTimer: TTimer;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
MoveTimer: TTimer;
StatusLabel: TLabel;
procedure ClickTimerTimer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure MoveTimerTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function LLKeyProc(nCode: integer; wp: WPARAM; lp: LPARAM): LRESULT; stdcall;
var
Form1: TForm1;
hHook: HHOOK = 0;
isEmulationActive: Boolean = False;
moveDirection: Integer = 1;
originalPos: TPoint;
implementation
{$R *.lfm}
{ TForm1 }
procedure SimulateLeftClick;
var
Inputs: array[0..1] of TInput;
begin
FillChar(Inputs, SizeOf(Inputs), 0);
Inputs[0].Itype := INPUT_MOUSE;
Inputs[0].mi.dwFlags := MOUSEEVENTF_LEFTDOWN;
Inputs[1].Itype := INPUT_MOUSE;
Inputs[1].mi.dwFlags := MOUSEEVENTF_LEFTUP;
SendInput(2, Inputs[0], SizeOf(TInput));
end;
function LLKeyProc(nCode: integer; wp: WPARAM; lp: LPARAM): LRESULT; stdcall;
var
vk: DWORD;
begin
Result := 0;
if nCode = HC_ACTION then
begin
vk := PLowLevelKeyboardProc(lp)^.vkCode;
if (wp = WM_KEYDOWN) or (wp = WM_SYSKEYDOWN) then
begin
case vk of
VK_F3:
begin
if not isEmulationActive then
begin
isEmulationActive := True;
Form1.StatusLabel.Caption := 'Статус: РАБОТАЕТ (F4 - стоп)';
Form1.StatusLabel.Font.Color := clGreen;
GetCursorPos(originalPos);
moveDirection := 1;
Form1.ClickTimer.Interval := StrToIntDef(Form1.Edit1.Text, 120);
Form1.MoveTimer.Interval := StrToIntDef(Form1.Edit3.Text, 1000);
Form1.ClickTimer.Enabled := True;
Form1.MoveTimer.Enabled := True;
end;
end;
VK_F4:
begin
if isEmulationActive then
begin
isEmulationActive := False;
Form1.StatusLabel.Caption := 'Статус: ОСТАНОВЛЕНО (F3 - старт)';
Form1.StatusLabel.Font.Color := clRed;
Form1.ClickTimer.Enabled := False;
Form1.MoveTimer.Enabled := False;
end;
end;
else
Result := CallNextHookEx(hHook, nCode, wp, lp);
end;
end
else
Result := CallNextHookEx(hHook, nCode, wp, lp);
end
else
Result := CallNextHookEx(hHook, nCode, wp, lp);
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text := '120';
Edit2.Text := '100';
Edit3.Text := '1000';
StatusLabel.Caption := 'Статус: ОСТАНОВЛЕНО (F3 - старт)';
StatusLabel.Font.Color := clRed;
hHook := SetWindowsHookEx(WH_KEYBOARD_LL, @LLKeyProc, HInstance, 0);
end;
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
if hHook <> 0 then
UnhookWindowsHookEx(hHook);
end;
procedure TForm1.ClickTimerTimer(Sender: TObject);
begin
if isEmulationActive then
begin
SimulateLeftClick;
end;
end;
procedure TForm1.MoveTimerTimer(Sender: TObject);
var
distance: Integer;
currentPos: TPoint;
begin
if not isEmulationActive then
Exit;
distance := StrToIntDef(Edit2.Text, 100);
GetCursorPos(currentPos);
if moveDirection = 1 then
begin
SetCursorPos(originalPos.X + distance, currentPos.Y);
moveDirection := -1;
end
else
begin
SetCursorPos(originalPos.X, currentPos.Y);
moveDirection := 1;
SetCursorPos(originalPos.X, currentPos.Y + 5);
GetCursorPos(originalPos);
end;
end;
end.
|