Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3879696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:45:23+00:00 2026-05-19T22:45:23+00:00

I want to use Mono to allow my C# program (currently WPF but will

  • 0

I want to use Mono to allow my C# program (currently WPF but will change it to Windows Forms or Silverlight so that Mono will work) that currently works in Windows to work on a Mac.

I use native windows code to detect when a mouse is clicked, and also to click the mouse, like so:

[DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
[DllImport("User32.dll")]
public static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);

In order for this to work on a Mac I need to first be able to detect whether the program is running on a Mac or in Windows, and then run the appropriate code for detecting whether a mouse is clicked, or for clicking the mouse. Something like:

if (runningInWindows())
{
    // Windows mouse click...
    System.Windows.Forms.Cursor.Position = new System.Drawing.Point(X, Y);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

    // Or if I want to detect a mouse click...
    bool mouseClicked = GetAsyncKeyState(System.Windows.Forms.Keys.LButton) != 0;
}
else
{
    // Running on a Mac, so do Mac mouse click...
    // Or detect a mouse click on a Mac...
}

Essentially I have 3 questions:

  1. How do you click the mouse on a Mac? (equivalent of mouse_event)
  2. How do you detect a mouse click on a Mac? (equivalent of GetAsyncKeyState)
  3. How do you detect which Operating System your application is running in?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:45:23+00:00Added an answer on May 19, 2026 at 10:45 pm

    Detecting the operating system is easy, you can find some platform detection code here.

    The other two are harder. You’d have to look at Apple’s native Carbon or Cocoa APIs and figure out how to do the things you want, then P/Invoke those APIs. FWIW, I don’t know whether it’s actually possible to control the mouse with public API. There do seem to be some sites around that explain how to do some of this stuff.

    For a start, getting the mouse position seems to be possible via HIGetMousePosition (Carbon) or [NSEvent mouseLocation] (Cocoa). Although a lot of high-level Carbon APIs are deprecated, it still forms the core of the low-level C API used by Cocoa. It could be tricky figuring out how to read Carbon events and extract information from them, OTOH Cocoa means interop with Objective-C, which is more complicated than P/Invoke – but MonoMac has some APIs that can make that easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use the Web Browser control within an mono application, but when
I want to use the MultipleLookupField control in a web page that will run
I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom
I want to use the functions exposed under the OpenGL extensions. I'm on Windows,
Have you heard of real ASP.NET applications that use Mono? What problems do they
I want use math operations in XAML code but I dont know how?
Below is my stored procedure. I want use stored procedure select all row of
I want to use Powershell to write some utilities, leveraging our own .NET components
I want to use the Publish.GacRemove function to remove an assembly from GAC. However,
I want to use CodeDOM to both declare and initialize my static field in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.