Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   FreePascal (https://www.delphipraxis.net/74-freepascal/)
-   -   Lazarus Tastaturhook (https://www.delphipraxis.net/152419-lazarus-tastaturhook.html)

erich.wanker 22. Jun 2010 11:09

Lazarus Tastaturhook
 
Hallo Community,

ich versuch schon einige Zeit, einen Tastaturhook für 64Bit Windows zu schreiben:

Situation: Ein Barcodescanner schickt Ascii 20 (hardwaredivice 4) - anschließend den EAN Code - abschließend ascii 13

Die in Delphi7 geschriebene 32bit dll funktioniert soweit einwandfrei..
( http://www.delphipraxis.net/150184-t...c-lazarus.html

Mit TD2X64Bridge bin ich leider nich zu einem Ergebnis gekommen..
Mit der portierung meines Delphi7 Codes bin ich auch nicht zu einem Ergebnis gekommen...

Hat jemand zufällig einen Link zu einem lauffähigen (rein für Windows) Tastaturhook für Lazarus IDE 0.9.28.2 ? (nicht mal nen Beispielsource find ich :oops: )

Vielen Dank

Erich

erich.wanker 22. Jun 2010 14:29

AW: Lazarus Tastaturhook
 
.. OK . es geht ! :-)

Hab auf Desktop XP 32bit
Hab auf Notebook Win7 64 Bit
Auf beiden Lazarus installiert..
am XP hab ich stratHook und StopHook mit der Zahl 32 erweitert und das Projet als versatile32 gespeichert und compiliert
am Win7 hab ich stratHook und StopHook mit der Zahl 64 erweitert und das Projet als versatile64 gespeichert und compiliert

In meiner 32Bit Delphi 7 Anwendung (für die der Tastaturhook ist..) hab ich

Delphi-Quellcode:
    procedure DllMessage(var Msg: TMessage); message WM_USER + 8765;
  end;

    function StartHook32(AppHandle: HWND): Boolean; stdcall; external 'versatile32.dll';
    function StopHook32: Boolean; stdcall; external 'versatile32.dll';
    function StartHook64(AppHandle: HWND): Boolean; stdcall; external 'versatile64.dll';
    function StopHook64: Boolean; stdcall; external 'versatile64.dll';

Um zu entscheiden, welche DLL ich verwende:

Delphi-Quellcode:
function TVersatile_main_handle.IsWow64: Boolean;
type
  TIsWow64Process = function( // Type of IsWow64Process API fn
    Handle: Windows.THandle; var Res: Windows.BOOL
  ): Windows.BOOL; stdcall;
var
  IsWow64Result: Windows.BOOL;     // Result from IsWow64Process
  IsWow64Process: TIsWow64Process; // IsWow64Process fn reference
begin
    // Try to load required function from kernel32
    IsWow64Process := Windows.GetProcAddress(
      Windows.GetModuleHandle('kernel32.dll'), 'IsWow64Process'
    );
    if Assigned(IsWow64Process) then
    begin
      // Function is implemented: call it
      if not IsWow64Process(
        Windows.GetCurrentProcess, IsWow64Result
      ) then
        raise SysUtils.Exception.Create('IsWow64: bad process handle');
      // Return result of function
      Result := IsWow64Result;
    end
    else
    // Function not implemented: can't be running on Wow64
    Result := False;

    if result = true then   gl_st_osbit := '64 Bit';
    if result = false then  gl_st_osbit := '32 Bit';
end;
Start Hook:
Delphi-Quellcode:
    if gl_st_osbit = '64 Bit' then StartHook32(handle);
    if gl_st_osbit = '32 Bit' then StartHook64(handle);
Stop Hook
Delphi-Quellcode:
    if gl_st_osbit = '64 Bit' then StopHook32;
    if gl_st_osbit = '32 Bit' then StopHook64;






Der FreePascal Code für die DLL´s:

Delphi-Quellcode:
library Versatile32;


{$mode objfpc}{$H+}

{$IFDEF WINDOWS}{$R Versatile32.rc}{$ENDIF}

uses
 Classes,
 Windows,
 ActiveX,
 ShlObj,
 Messages,
 SysUtils;



var
  HookHandle: Cardinal = 0;
  AppHandle: HWND;

function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
  Result := CallNextHookEx(HookHandle,
                           nCode,
                           wParam,
                           lParam);
  if nCode = HC_NOREMOVE then
    Exit;
// if nCode = HC_ACTION then

if wParam = VK_F4 then
begin
    PostMessage(FindWindow(nil,'Versatile'),
                WM_USER + 8765,
                300,
                0);
end
else
begin
    PostMessage(FindWindow(nil,'Versatile'),
                WM_USER + 8765,
                wParam,
                lParam);
end;

end;

function StartHook32(ApplicationHandle: HWND): Boolean; stdcall;
begin
  Result := False;
  if HookHandle = 0 then
    begin
    HookHandle := SetWindowsHookEx(WH_KEYBOARD,
                                   @KeyboardHookProc,
                                   HInstance,
                                   0);
    AppHandle := ApplicationHandle;
    Result := TRUE;
    end;
end;

function StopHook32: Boolean; stdcall;
begin
  Result := UnhookWindowsHookEx(HookHandle);
  HookHandle := 0;
end;

exports
  StartHook32,
  StopHook32;
end.

erich.wanker 22. Jun 2010 16:25

AW: Lazarus Tastaturhook
 
Neues Problem: :-(

Die ASCII Werte stimmen nicht ??

Der Barcode sendet (wurde überprüft!) ascii20 am Anfang (Hardwaredevice 4) - und ankommen tut eine Kombination aus ascii84 und 17 ???



ach ja: KeyUp rausfiltern:

Delphi-Quellcode:
    if ((lParam and (1 shl 30)) <> 0) then
    begin  

    end;



Hat jemand eine idee ?

Erich


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:39 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz