Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi [Vista][gelöst] Maus Ereignisse ausserhalb eigener Anwendung (https://www.delphipraxis.net/123847-%5Bvista%5D%5Bgeloest%5D-maus-ereignisse-ausserhalb-eigener-anwendung.html)

The Riddler 10. Nov 2008 09:32


[Vista][gelöst] Maus Ereignisse ausserhalb eigener Anwendung
 
Dieses seltsame Betriebssystem bringt mich langsam wirklich zur Verzweiflung. :evil:

Alles was ich möchte, ist auf Mausereignisse zu reagieren. Aber leider, tut sich Herr Vista da etwas beschränkt. Die Saucen vom SwissDelphiCenter (Maus Ereignisse ausserhalb der eigenen Anwendung abfangen?) funktionieren wunderbar unter XP.

Herr Vista sagt nur:
Zitat:

---------------------------
crap
---------------------------
No Journal Hook availible
---------------------------
OK
---------------------------
Gibt es mittlerweile einen Workaround oder irgendeine Möglichkeit, sowas unter Vista zu realisieren? Je nach Aufwand wäre ich auch bereit für eine tadellos funktionierende Lösung ein paar Euro zu zahlen.

Grüße

Bernhard Geyer 10. Nov 2008 09:45

Re: [Vista] Maus Ereignisse ausserhalb der eigenen Anwendung
 
Hast du mal Testhalber UAC deaktiviert? Aktive UAC wird entsprechend die Hookmöglichkeiten einschränken.

The Riddler 10. Nov 2008 09:54

Re: [Vista] Maus Ereignisse ausserhalb der eigenen Anwendung
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ich habe leider kein Vista und kann das daher nicht recht testen. Mein Tester sagte mir allerdings, dass es selbst mit Adminrechten nicht will. Aber ich frag nochmal nach.

Ich hab das Testprogramm mal angehangen, bei Rechtsklick & Linksklick erscheint die Aktion in dem Memo. Wäre dankbar wenn du das mal ohne UAC testen könntest. Thx

Bernhard Geyer 10. Nov 2008 10:11

Re: [Vista] Maus Ereignisse ausserhalb der eigenen Anwendung
 
Zitat:

Zitat von The Riddler
Ich habe leider kein Vista und kann das daher nicht recht testen.

Dann wäre es Zeit eine VM damit aufzusetzen ...

Zitat:

Zitat von The Riddler
Mein Tester sagte mir allerdings, dass es selbst mit Adminrechten nicht will. Aber ich frag nochmal nach.

Solange UAC aktiv ist werden Prozesse mit und ohne Adminrechte gegeneinander abgeschottet um z.B. deaktivierung/umkonfiguration Firewall darüber zu verhindern (Maustastensimulation).

jfheins 10. Nov 2008 10:16

Re: [Vista] Maus Ereignisse ausserhalb der eigenen Anwendung
 
Also ich würde kein Programm haben wolleen, dass vorraussetzt, dass die UAC abgeschaltet ist.

Wie Ollis-Hook Demo beweist, geht es mit aktivierter UAC und ohne nach adminrechten zu gieren wunderbar, alle möglichen Infos über Maus und Tastatur zu bekommen ;)

taaktaak 10. Nov 2008 10:23

Re: [Vista] Maus Ereignisse ausserhalb der eigenen Anwendung
 
Moin, Moin.
Könnte so etwas auch gebrauchen.
@jfheins : Ist "Ollis-Hook Demo" das Beispiel von den Schweizern?

DeddyH 10. Nov 2008 10:29

Re: [Vista] Maus Ereignisse ausserhalb der eigenen Anwendung
 
Schau doch mal auf Ollis Seite, evtl. ist das hier gemeint: http://assarbad.net/en/stuff/tutorials/hooks/

The Riddler 10. Nov 2008 11:04

Re: [Vista][gelöst] Maus Ereignisse ausserhalb eigener Anwen
 
Ollis Beispiel ist zwar sehr geil, aber leider für Laien absolut undurchblickbar.

Bin trotzdem gerade auf die Lösung gestoßen: http://www.delphi3000.com/articles/article_3895.asp?SK=
Klappt unter Vista auch, bis auf das Mausrad. Fix anyone?

Falls die Seite mal down ist:
DLL-Code:
Delphi-Quellcode:
library HookMouse;

{Demo de Hook de Ratón a nivel de sistema, Radikal.}

uses Windows, Messages;

const
CM_MANDA_DATOS = WM_USER + $1000;

type
TCompartido = record
   Receptor,
   wHitTestCode,
   x,y,
   Ventana        : hwnd;
end;
PCompartido  =^TCompartido;


var
HookDeMouse : HHook;
FicheroM    : THandle;
Compartido  : PCompartido;


function CallBackDelHook( Code   : Integer;
                          wParam : WPARAM;
                          lParam : LPARAM
                          )      : LRESULT; stdcall;

var
  DatosMouse    : PMouseHookStruct;
  Intentos      : integer;

{Esta es la funcion CallBack a la cual llamará el hook.}
{This is the CallBack function called by he Hook}
begin
{Si hay un nuevo evento de raton...}
{if there is a new mouse event...}
if code=HC_ACTION then
begin
  {Miramos si existe el fichero}
  {if the mapfile exists}
  FicheroM:=OpenFileMapping(FILE_MAP_WRITE,False,'ElReceptor');
  {Si no existe, no enviamos nada a la aplicacion receptora}
  {If dont, send nothing to receiver application}
  if FicheroM<>0 then
  begin
    Compartido:=MapViewOfFile(FicheroM,FILE_MAP_WRITE,0,0,0);

    {Apuntamos hacia los datos del evento del raton}
    DatosMouse:=Pointer(lparam);

    {Los guardamos en el fichero de memoria}
    Compartido^.Ventana:=DatosMouse^.hwnd;
    Compartido^.x:=DatosMouse^.pt.x;
    Compartido^.y:=DatosMouse^.pt.y;

    {Avisamos al receptor para que atienda el nuevo evento}
    {Say to receiver that there is a new event}
    PostMessage(Compartido^.Receptor,CM_MANDA_DATOS,wParam,lParam);

    UnmapViewOfFile(Compartido);
    CloseHandle(FicheroM);
  end;
end;
{Llamamos al siguiente hook de la cadena}
{call to next hook of the chain}
Result := CallNextHookEx(HookDeMouse, Code, wParam, lParam)
end;

procedure HookOn; stdcall;
{Procedure que instala el hook}
{procedure for install the hook}
begin
  HookDeMouse:=SetWindowsHookEx(WH_MOUSE, @CallBackDelHook, HInstance , 0);
end;

// stops this type of watch
procedure HookOff; stdcall;
begin
{procedure para desinstalar el hook}
{procedure to uninstall the hook}
  UnhookWindowsHookEx(HookDeMouse);
end;

exports
{Exportamos las procedures...}
{Export the procedures}
HookOn,
HookOff;

begin
end.
Programm-Code:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

const
  NombreDLL      = 'HookMouse.dll';
  CM_MANDA_DATOS = WM_USER + $1000;


type
TCompartido = record
   Receptor,
   wHitTestCode,
   x,y,
   Ventana        : hwnd;
end;
PCompartido  =^TCompartido;
THookMouse=procedure; stdcall;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FicheroM      : THandle;
    Compartido    : PCompartido;
    HandleDLL     : THandle;
    HookOn,
    HookOff       : THookMouse;


    procedure LlegaDelHook(var message: TMessage); message CM_MANDA_DATOS;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  HandleDLL:=LoadLibrary( PChar(ExtractFilePath(Application.Exename)+
                                NombreDLL ) );
  if HandleDLL = 0 then raise Exception.Create('No se pudo cargar la DLL');

  @HookOn :=GetProcAddress(HandleDLL, 'HookOn');
  @HookOff:=GetProcAddress(HandleDLL, 'HookOff');

  if not assigned(HookOn) or
     not assigned(HookOff) then
     raise Exception.Create('No se encontraron las funciones en la DLL'+#13+
                            'Cannot find the required DLL functions');

  {Creamos el fichero de memoria}
  FicheroM:=CreateFileMapping( $FFFFFFFF,
                              nil,
                              PAGE_READWRITE,
                              0,
                              SizeOf(Compartido),
                              'ElReceptor');

   {Si no se creó el fichero, error}
   if FicheroM=0 then
     raise Exception.Create( 'Error al crear el fichero'+
                             '/Error while create file');

   {Direccionamos nuestra estructura al fichero de memoria}
   Compartido:=MapViewOfFile(FicheroM,FILE_MAP_WRITE,0,0,0);

   {Escribimos datos en el fichero de memoria}
   Compartido^.Receptor:=Handle;
   HookOn;
end;

procedure TForm1.LlegaDelHook(var message: TMessage);
var
  DatosMouse    : PMouseHookStruct;
  NombreVentana : array [0..200] of char;
  Accion        : string;
begin
  with Compartido^ do
  begin
    {Coordenadas del raton}
    {Mouse coordinates}
    Label1.caption:='['+IntToStr(x)+':'+IntToStr(y)+']';
  end;
  {Nombre de la ventana donde esta el raton}
  {Window Name}
  GetWindowText(Compartido^.Ventana,@NombreVentana,200);
  Label2.Caption:=NombreVentana;

  case Message.wParam of
    WM_LBUTTONDBLCLK    : Accion:='WM_LBUTTONDBLCLK ';
    WM_LBUTTONDOWN : Accion:='WM_LBUTTONDOWN   ';
    WM_LBUTTONUP        : Accion:='WM_LBUTTONUP     ';
    WM_MBUTTONDBLCLK    : Accion:='WM_MBUTTONDBLCLK ';
    WM_MBUTTONDOWN      : Accion:='WM_MBUTTONDOWN   ';
    WM_MBUTTONUP        : Accion:='WM_MBUTTONUP     ';
    WM_MOUSEMOVE        : Accion:='WM_MOUSEMOVE     ';
    WM_NCHITTEST        : Accion:='WM_NCHITTEST     ';
    WM_NCLBUTTONDBLCLK  : Accion:='WM_NCLBUTTONDBLCLK';
    WM_NCLBUTTONDOWN    : Accion:='WM_NCLBUTTONDOWN ';
    WM_NCLBUTTONUP      : Accion:='WM_NCLBUTTONUP   ';
    WM_NCMBUTTONDBLCLK  : Accion:='WM_NCMBUTTONDBLCLK';
    WM_NCMBUTTONDOWN    : Accion:='WM_NCMBUTTONDOWN ';
    WM_NCMBUTTONUP      : Accion:='WM_NCMBUTTONUP   ';
    WM_NCMOUSEMOVE      : Accion:='WM_NCMOUSEMOVE   ';
    WM_NCRBUTTONDBLCLK  : Accion:='WM_NCRBUTTONDBLCLK';
    WM_NCRBUTTONDOWN    : Accion:='WM_NCRBUTTONDOWN ';
    WM_NCRBUTTONUP      : Accion:='WM_NCRBUTTONUP   ';
    WM_RBUTTONDBLCLK    : Accion:='WM_RBUTTONDBLCLK ';
    WM_RBUTTONDOWN      : Accion:='WM_RBUTTONDOWN   ';
    WM_RBUTTONUP        : Accion:='WM_RBUTTONUP     ';
  end;
  Memo1.Lines.Append(Accion);

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
{Desactivamos el Hook}
{Uninstall the Hook}
if Assigned(HookOff) then HookOff;

{Liberamos la DLL}
{Free the DLL}
if HandleDLL<>0 then
  FreeLibrary(HandleDLL);

{Cerramos la vista del fichero y el fichero}
{Close the memfile and the View}
if FicheroM<>0 then
begin
   UnmapViewOfFile(Compartido);
   CloseHandle(FicheroM);
end;
end;


end.

The Riddler 10. Nov 2008 11:08

Re: [Vista][gelöst] Maus Ereignisse ausserhalb eigener Anwen
 
Für das Mausrad einfach noch ein
Delphi-Quellcode:
    WM_MOUSEWHEEL       : Accion:='WM_WHEEL     ';
einfügen.

The Riddler 10. Nov 2008 15:03

Re: [Vista][gelöst] Maus Ereignisse ausserhalb eigener Anwen
 
Ein Problem gibt es noch: Wie kann ich nun noch herausfinden, ob das Rad nach unten oder oben gedreht wird? :gruebel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:14 Uhr.
Seite 1 von 2  1 2      

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