Autor Beitrag
Killmag10
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Do 07.10.04 17:27 
Hi

ich hab folgendes prob

Wie kann ich auf ereignisse der maus von auserhalb reagieren ?

also wenn nehmand auserhalb der form Klickt.


also setzten is ja kein prob mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  x:=600;
  y:=520;   
  setcursorpos(x,y);
  mouse_event(MOUSEEVENTF_leftDOWN,x,y,0,0);
  mouse_event(MOUSEEVENTF_leftUP,x,y,0,0);


mfg Killmag10

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: Do 07.10.04 17:54 
Hmmm... riecht mir stark nach systemweitem Maushook...



MrSaint

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Do 07.10.04 17:55 
Hi,

Stickwort: Mouse Hook.
Wenn du möchtest, kann ich dir ein Beispiel e-Mailen.

Kann im DF leider keine Anhänge einfügen.
Killmag10 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Do 07.10.04 17:58 
toms hat folgendes geschrieben:
Hi,

Stickwort: Mouse Hook.
Wenn du möchtest, kann ich dir ein Beispiel e-Mailen.

Kann im DF leider keine Anhänge einfügen.


Jo wehre nett.

meine email is dietrich.lars@web.de

danke schonmal

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
Killmag10 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Do 07.10.04 18:37 
Ich hab die mail bekommen danke;

der code ist jedoch sehr groß;

gibt es einen kleineren ?

es muss nicht ausgelsen werden auf welsche anwendung geklickt wurde sonder blos das ein klick stattgefunden hatt mehr nicht, und vieleicht noch die position aber das geht ja mit TMouse.

mfg. Killmag10

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Do 07.10.04 18:42 
Ich wüsste nicht. Aber zum besseren Verständnis kann ich dir Assarbads Hook-Tutorial wärmstens empfehlen:
assarbad.net/en/stuff/tutorials/hooks/

_________________
JSXGraph
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Do 07.10.04 18:44 
Hi,

Kannst den Code auf folgendes reduzieren:


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
unit HookDemo_f;

interface

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

type
  TfrmHookDemo = class(TForm)
    Panel1: TPanel;
    btnClose: TButton;
    Memo1: TMemo;
    btnGetMessageSet: TButton;
    btnGetMessageUnSet: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure btnGetMessageSetClick(Sender: TObject);
    procedure btnGetMessageUnSetClick(Sender: TObject);
  private
  public
    procedure WMGM(var Message: TMessage); message MSG_GETMESSAGE;
  end;

const
  HOOKDLL = 'GetMessage.dll';
var
  frmHookDemo: TfrmHookDemo;

procedure GMSetHook;
procedure GMUnSetHook;
procedure GMSetMainHandle(Handle: HWND);


implementation

{$R *.DFM}

{DEFINE RWFPCHOICE}

procedure GMSetHook; external HOOKDLL Name 'SetHook';
procedure GMUnSetHook; external HOOKDLL Name 'UnSetHook';
procedure GMSetMainHandle; external HOOKDLL Name 'SetMainHandle';

// Maus Nachrichten abfangen
procedure TfrmHookDemo.WMGM(var Message: TMessage);
begin
  case Message.lParam of
    wm_lButtonDown:
      begin
        Memo1.Lines.Add('Maus Button Down ' + Format('(%d , %d)',
          [Mouse.CursorPos.X, Mouse.CursorPos.Y]));
      end;
    wm_lButtonUp:
      begin
        Memo1.Lines.Add('Maus Button Up ' + Format('(%d , %d)',
          [Mouse.CursorPos.X, Mouse.CursorPos.Y]));
      end;
  end;
end;


procedure TfrmHookDemo.FormDestroy(Sender: TObject);
begin
  GMSetMainHandle(0);
  GMUnSetHook;
end;

// Hook starten
procedure TfrmHookDemo.btnGetMessageSetClick(Sender: TObject);
begin
  GMSetMainHandle(Handle);
  GMSetHook;
end;

// Hook stoppen
procedure TfrmHookDemo.btnGetMessageUnSetClick(Sender: TObject);
begin
  GMUnsetHook;
end;

end.
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Do 07.10.04 19:11 
Hier der Vollständigkeit halber und für Interessierte noch der Code der dll:


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
library GETMESSAGE;

uses
  SysUtils,
  Windows,
  HookDemoConst,
  Messages;

procedure SetHook; export; forward;
procedure UnSetHook; export; forward;
procedure SetMainHandle(Handle: HWND); export; forward;

{$j+}
exports
  SetHook index 1,
  UnSetHook index 2,
  SetMainHandle index 3;

type
  PHookRec = ^THookRec;
  THookRec = record
    MainWindow: HWND;
    HookID: HHOOK;
  end;

const
  rHookRec: PHookRec = nil;

procedure SetMainHandle(Handle: HWND);
begin
  rHookRec^.MainWindow := Handle;
end;

// WndProcRet hook proc
function WNDPROCRET_HookProc(nCode: Integer; iWPARAM: wParam; iLPARAM: lParam): LResult;
  stdcall; far;
var
  ReturnStructure: PMSG;
begin
  if nCode >= 0 then 
  begin
    ReturnStructure := PMSG(iLParam);

    if rHookRec^.MainWindow <> 0 then
      SendMessage(rHookRec^.MainWindow, MSG_GETMESSAGE, ReturnStructure^.HWND,
        ReturnStructure^.message);
  end 
  else 
  begin
    CallNextHookEx(rHookRec^.HookID, nCode, iwParam, ilParam);
  end;
  Result := 0;
end;

procedure SetHook;
begin
  rHookRec^.HookID := SetWindowsHookEx(WH_GETMESSAGE, @WNDPROCRET_HookProc, hInstance, 0);
end;

procedure UnSetHook;
begin
  UnHookWindowsHookEx(rHookRec^.HookID);
end;

procedure EntryPointProc(Reason: Integer);
const
  hMapObject: THandle = 0;
begin
  case reason of
    DLL_PROCESS_ATTACH:
      begin
        hMapObject := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0,
          SizeOf(THookRec), '_GETMESSAGE');
        rHookRec := MapViewOfFile(hMapObject, FILE_MAP_WRITE, 0, 0, 0);
      end;

    DLL_PROCESS_DETACH:
      begin
        try
          UnMapViewOfFile(rHookRec);
          CloseHandle(hMapObject);
        except
        end;
      end;

    DLL_THREAD_ATTACH:
      begin
      end;

    DLL_THREAD_DETACH:
      begin
      end;
  end;
end;
{$j-}
begin
  DllProc := @EntryPointProc;
  EntryPointProc(DLL_PROCESS_ATTACH);
end.



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
unit HookDemoConst;

interface

uses
  Messages;

const
  MSG_GETMESSAGE = WM_USER + 4;

implementation

end.
Killmag10 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Fr 08.10.04 09:28 
danke genau das ist es was ich gesucht habe :wink:

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Fr 08.10.04 10:06 
naja oder man nimmt

GetCursorPos
GetAsyncKeyState

in nem thread, weil immer nen maushook zu schreiben und dann zwischen dll und exe daten austaushen ist halt net so einfach, aber wenns denn so sein muss...
k.kuh
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win XP
Delphi 6
BeitragVerfasst: Mi 08.02.06 09:46 
Hi! Ich weiss, das ist schon ein aelterer thread, vielleicht kann mir ja trotzdem jemand helfen... ich benutze den oben geposteten dll quelltext und habe auch keine probleme, mit dem darstellen der curserposition im memo. wenn ich nun aber auf buttonup oder buttondown eine prozedur aufrufe, scheint der hook nicht wieder geloest zu werden, alle fenster frieren ein und ich muss manuell resetten, da noch nichteinmal der taskmanager funktioniert. ist es nun nicht moeglich mit dem obigen code fuer die dll prozeduren aufzurufen????

danke schoneinmal im vorraus!