AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Lazarus Tastaturhook

Ein Thema von erich.wanker · begonnen am 22. Jun 2010 · letzter Beitrag vom 22. Jun 2010
Antwort Antwort
Benutzerbild von erich.wanker
erich.wanker

Registriert seit: 31. Jan 2008
Ort: im schönen Salzburger Land
454 Beiträge
 
Delphi XE4 Professional
 
#1

Lazarus Tastaturhook

  Alt 22. Jun 2010, 11:09
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 )

Vielen Dank

Erich
Erich Wanker - for life:=1971 to lebensende do begin ..
  Mit Zitat antworten Zitat
Benutzerbild von erich.wanker
erich.wanker

Registriert seit: 31. Jan 2008
Ort: im schönen Salzburger Land
454 Beiträge
 
Delphi XE4 Professional
 
#2

AW: Lazarus Tastaturhook

  Alt 22. Jun 2010, 14:29
.. 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 Bitthen StartHook32(handle);
    if gl_st_osbit = '32 Bitthen StartHook64(handle);
Stop Hook
Delphi-Quellcode:
    if gl_st_osbit = '64 Bitthen StopHook32;
    if gl_st_osbit = '32 Bitthen 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 - for life:=1971 to lebensende do begin ..
  Mit Zitat antworten Zitat
Benutzerbild von erich.wanker
erich.wanker

Registriert seit: 31. Jan 2008
Ort: im schönen Salzburger Land
454 Beiträge
 
Delphi XE4 Professional
 
#3

AW: Lazarus Tastaturhook

  Alt 22. Jun 2010, 16:25
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
Erich Wanker - for life:=1971 to lebensende do begin ..
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:32 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz