5

I have written an application (wpf - will Mono translate this for a Mac?) that I wish to somehow port across to Mac OS X. This application involves using user32.dll to perform a mouse click (something like this):

[DllImport("user32.dll")]
    static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

I have heard Mono is useful for making applications for multiple platforms - is there a way that I can use this to make my code compatible with a Mac?

If not, is there a way that I can invoke a mouse click using the Mac equivalent of user32.dll? And a way to detect whether the program is running in Windows or Mac OS to choose which bit of code to run?

Jack
  • 2,153
  • 5
  • 28
  • 43
  • are you trying to generate the mouse click against something in your application, or against another application – Mark Hall Feb 01 '11 at 16:38
  • I'm trying to click in another application - my app is minimised while it runs. – Jack Feb 01 '11 at 20:17
  • Mono is not compatible with WPF. You need to use WinForms. I have spent a lot of time googling a Mac equivalent of user32.dll, I was unable to find a 'managed' version of mouse_event. –  Apr 03 '11 at 10:23

4 Answers4

1

Mono currently does not plan to support WPF see Link.
Take a look at this SO question to see if it helps and you may want to look into using Silverlight since it is supported by Microsoft on the Mac.

Community
  • 1
  • 1
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
1

Also you are calling a Win32 native function - those are not supported on Mac. Your best bet would be using cross-platform .NET-strict code.

Den
  • 16,686
  • 4
  • 47
  • 87
  • Do you know what .NET-strict code I can use to perform a mouse click? I have looked into it before but could not find how to do it without using user32.dll... – Jack Feb 01 '11 at 08:51
  • It is a capability tied to the system - you have to invoke the API directly in Windows because there is no .NET implementation for it. There is similar capability available for Mac (http://stackoverflow.com/questions/1483657/performing-a-double-click-using-cgeventcreatemouseevent) but I am not sure you can use it in Mono. – Den Feb 01 '11 at 16:02
0

You can try looking at Apple's CG API, there is a function CGEventCreateMouseEvent

Leo Correa
  • 19,131
  • 2
  • 53
  • 71
Jenny0412
  • 1
  • 1
0

Mono does not support WPF and currently has no future plans to support it. I looked into this on the weekend myself.

If you are going to use mono with GUI applications, I advise you use WinForms instead as this is implemented in Mono.

Here is the full list of Mono implemented features - http://mono-project.com/Compatibility

JonWillis
  • 3,146
  • 5
  • 32
  • 54
  • This does not answer the question; he is asking if there is an equivalent way to simulate a mouse click using Mono on OS X, not whether it is possible to port over a WPF application. – Callum Rogers Jan 12 '14 at 20:27