[Mono-list] Low level mouse hook via SetWindowsHookEx

Ivan Zlatev contact at i-nz.net
Sat Jul 4 17:20:08 EDT 2009


Hello,

Those are native Windows system dlls and obviously they aren't
available on Linux. You will have to research on how to do this sort
of stuff using native low level X11 / xlib stuff. I have no idea how
to do this myself but some good keywords for your google searches are:
X11, xlib, XRecord, XTest, evdev. It might be a good idea to also look
at what the accessibility tools on Linux do to hook into
mouse/keyboard. Last but not least if you indeed end up using xlib to
save you time wrapping the native code there are already ready to use
P/Invoke signatures in Mono's WinForms code at
http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs?view=markup
and the xlib structures in C# that they require are here -
http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/X11Structs.cs?view=markup
.


Kind Regards,

Ivan Zlatev
http://ivanzlatev.com



On Sat, Jul 4, 2009 at 9:40 PM, cstockton<chrisstocktonaz at gmail.com> wrote:
>
> Hello,
>
> I am porting a app I want to distribute for free in Linux. It clicks for
> users with RSI (Repetitive Stress Syndrome).
>
> Part of the application is monitoring the movement of the mouse and sending
> global clicks, this is window independent. I achieved this in C# under
> windows using :
>
> [code]
>        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError =
> true)]
>
>        private static extern IntPtr SetWindowsHookEx(int idHook,
> LowLevelProc lpfn, IntPtr hMod, uint dwThreadId);
>
>
>        ... (more imports)
>
>        [DllImport("user32.dll")]
>
>        static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint
> dwData, int dwExtraInfo);
>
>        // later I
>        SetWindowsHookEx(WH_MOUSE_LL, proc,
> GetModuleHandle(curModule.ModuleName), 0);
>
> [/code]
>
> The app is complete and runs great in windows, it builds okay in MonoDevelop
> but I get a exception when running :
>
> Unhandled Exception: System.EntryPointNotFoundException: GetModuleHandle
>  at (wrapper managed-to-native) Clicker.Form1:GetModuleHandle (string)
>  at Clicker.Form1.SetMouseHook (Clicker.LowLevelProc proc) [0x00014] in ..
> Form1.cs:173
>  at Clicker.Form1..ctor () [0x004d2] in .. Form1.cs:510
>  at (wrapper remoting-invoke-with-check) Clicker.Form1:.ctor ()
>  at Clicker.Program.Main () [0x00015] in .. Program.cs:18
>
> I am assuming I am missing some key steps in those unmanaged invokes, but am
> unsure (after much much much googling) how to achieve this. If I need to
> scrap the hooking into the user32/kernel32 and do the alternative in X11
> libraries of some sort I am okay with that.
>
> -Chris
>
> --
> View this message in context: http://www.nabble.com/Low-level-mouse-hook-via-SetWindowsHookEx-tp24337660p24337660.html
> Sent from the Mono - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>


More information about the Mono-list mailing list