[SOLVED] Keyboard hook lazarus / 21-General ---------------------------------------------------------------------- pcurtis · 2021-05-20 11:48 I use the following code to hook the keyboard. How can I make it "eat" the keypress? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode delphi}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,  Windows, LCLType, Menus, StdCtrls, ComCtrls, MyTimer, myled, MMSystem; type   { TForm1 }   TForm1 = class(TForm)    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    TrackBar1: TTrackBar;    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);  private    function Start: boolean;    function Stop: Boolean;    function IsStarted: Boolean;  public   end; var  Form1: TForm1;  llKeyboardHook: HHOOK = 0;  AHandle : HWND; implementation {$R *.lfm} procedure SendKey(Wnd, VK : Cardinal);begin  ShowWindow(Wnd, SW_SHOW);  SetForegroundWindow(Wnd);   keybd_event(VK,0,0,0);  keybd_event(VK,0,KEYEVENTF_KEYUP,0);end; function LowLevelKeyboardHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): HRESULT; stdcall;type  PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;  TKBDLLHOOKSTRUCT = packed record    vkCode: DWORD;    scanCode: DWORD;    flags: DWORD;    time: DWORD;    dwExtraInfo: DWORD;    AHandle : HWND;  end;var  pkbhs: PKBDLLHOOKSTRUCT;  bPASSON : boolean;begin  bPASSON := true;  pkbhs := PKBDLLHOOKSTRUCT(Pointer(lParam));  Form1.Label2.Caption := pkbhs^.vkCode.ToString;  Form1.Label4.Caption := pkbhs^.flags.ToString;     if ((pkbhs^.vkCode = 109)) then  //-      begin        Form1.TrackBar1.Position := Form1.TrackBar1.Position - 1;         bPASSON := False;      end;   if ((pkbhs^.vkCode = 107)) then   //+    begin      Form1.TrackBar1.Position := Form1.TrackBar1.Position + 1;      bPASSON := False;    end;   Result := CallNextHookEx(llKeyboardHook, 0, wParam, lParam);end; { TForm1 } function TForm1.Start: boolean;const  WH_KEYBOARD_LL = 13;begin  if llKeyboardHook = 0 then    llKeyboardHook := SetWindowsHookEx(WH_KEYBOARD_LL, @LowLevelKeyboardHook, HInstance, 0);  Result := (llKeyboardHook <> 0)end; function TForm1.Stop: Boolean;begin  Result := False;  if (llKeyboardHook <> 0) and UnhookWindowsHookEx(llKeyboardHook) then  begin    llKeyboardHook := 0;    Result := True;  end;end; function TForm1.IsStarted: Boolean;begin  Result := (llKeyboardHook <> 0)end; procedure TForm1.FormCreate(Sender: TObject);begin  if not Start then    MessageDlg('Cannot start the hook!', mtError, [mbOk], 0);  Label2.Caption := '0';  Label4.Caption := '0';end; procedure TForm1.FormDestroy(Sender: TObject);begin  if IsStarted then    Stop;end; end. ---------------------------------------------------------------------- balazsszekely · 2021-05-20 11:54 Like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if EatMe then   Result := -1else  Result := CallNextHookEx(llKeyboardHook, 0, wParam, lParam); ---------------------------------------------------------------------- pcurtis · 2021-05-20 13:43 Thanks. Works perfectly.