mouse-Events global einfangen

der_Brain

Grünschnabel
hallo community again!

ich such ja immer noch verzweifelt jemanden der mir helfen kann mein problem zu lösen.
ich versuche global die mouse-Events einzufangen, und hab jetzt im netz ein bissell code gefunden, der aber noch nich so ganz hinhaut.

das soll eine class werden die die Events (rechtsclick, linksclick, mittelclick, doppelclick) erkennt

und dann möchte ich aus einer anderen class auf die events zugreifen können, um sie dann in eine log-Datei zu schreiben

Code:
public class Win32Hook
{
 [DllImport("kernel32")]
 public static extern int GetCurrentThreadId();

 [DllImport( "user32", 
CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
 public static extern int  SetWindowsHookEx(
  HookType idHook,
  HOOKPROC lpfn,
  int hmod,
  int dwThreadId);

 public enum HookType
 {
  WH_MOUSE = 7
 }

 public delegate int HOOKPROC(int nCode, int wParam, int lParam);

 public void SetHook()
 {
  // set the keyboard hook
  SetWindowsHookEx(HookType.WH_MOUSE,
   new HOOKPROC(this.MyMouseProc),
   0,
   GetCurrentThreadId());
 }

 public int MyMouseProc(int nCode, int wParam, int lParam)
 {
  //Perform your process
  Console.WriteLine("Mouse");
  return 0;
 }
}

Win32Hook hook = new Win32Hook();
hook.SetHook();

In the callback procedure, you may call the GetChildAtPoint method to 
determine which control the mouse is on and perform the corresponding 
actions.

ich hoffe ihr könnt den code verstehen!
und sorry das ich keine ahnung von winapi hab, deshalb bitte verständliche antworten schreiben!

dank im voraus

mfg
der_Brain
 
Zurück