我想使用Mono來允許我的C#程序(目前是WPF,但會將其更改爲Windows窗體或Silverlight,以便Mono可以工作)在Mac上工作。鼠標在Mac OS中點擊並檢測哪個OS應用程序正在運行
我使用本機Windows代碼來檢測被點擊鼠標時,也以點擊鼠標,就像這樣:
[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);
爲了使這個在Mac上工作,我必須首先能夠檢測程序是在Mac上還是在Windows中運行,然後運行適當的代碼來檢測是否單擊鼠標或單擊鼠標。喜歡的東西:
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...
}
基本上我有3個問題:
- 你怎麼點擊Mac上的鼠標? (相當於mouse_event)
- 如何在Mac上檢測到鼠標點擊? (相當於GetAsyncKeyState)
- 如何檢測應用程序在哪個操作系統中運行?