且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Mac上的Mono下WinForms应用程序中检测键组合时出现问题

更新时间:2023-10-16 12:45:34

我遇到了同样的问题.尝试使用IRC并在Mono和MonoMac房间上向irc.gnome.org询问.非常有帮助的人.

显然使用 MonoMac ,它使您可以在Interface Builder中构建本机UI并帮助存根您要与之对话的后端C#代码(即MonoMac是与本机Mac对话的Mono,在Mac上是 not Mono running ;第二个是普通的Mono),Windows .Forms支持下降到了无用的地方-有人告诉我Windows.Forms本质上在Mac上是死机",安静的 [单音小虫] [错误75996] [Maj]新增-菜单项事件不是由快捷方式触发的

Mono上的Windows.Forms是如此接近工作,很容易想到它会支持您需要完成的工作,但是,imo,要使它具有足够的坚固性以供使用,而不仅仅是制作快速实用程序,这是一个错误. /p>

I'm trying to get a .net 2 Windows.Forms application running on the Mac using Mono. The application has key combination short cuts for all functions, which have pre-defined defaults and can be reconfigured by the user. The Form KeyDown event handler looks up the action to be performed.

My problem is relating the Modifiers and KeyCode to the actual keys pressed. I don't mind if some mapping needs to be added for the Mac, but I need at least 3 modifier keys. However of the 4 modifiers on the Mac, few seem to produce obvious results. I get: Shift - works as expected Ctrl - reports a different KeyCode, but with correct modifier (eg Ctrl+N has Modifiers = Control and KeyCode 14 = "RButton, Clear").
Alt - reports some other key, unmodified (eg Alt+R gives KeyCode = 168 = "BrowserRefresh") Cmd - reports as Alt with expected KeyCode (eg Cmd+N appears as Alt-N)

I presume that the Cmd key would normally be used where Ctrl is used on Windows. Can anyone advise which of the three Mac keys I should be trying to use? And most importantly how to parse the KeyEventArgs to consistently report a base key plus three optional modifiers?

Mono is the latest version (as of a week or two ago), and it's a MacBook Air, OS X 10.8.1 if that makes any difference.

I get the same issues. Try using IRC and asking at irc.gnome.org on rooms Mono and MonoMac. Very helpful folks.

Apparently with MonoMac, which lets you build a native UI in Interface Builder and helps stub out your backend C# code to talk to it (that is, MonoMac is Mono talking to native Mac, not Mono running on a Mac; the second is just plain Mono), Windows.Forms support has dropped to the wayside -- I was told that Windows.Forms is essentially "dead" on the Mac, and the quiet bugzilla page seems to support that. It really is quite buggy. I ran into SelectionBackColor not working in RichTextBox right off the bat, then menu accelerators not working reliably. Windows.Forms on Mac is alpha to beta quality, I think.

That said, for what's essentially a labor of love, a surprising amount of Windows.Forms works well, but I wouldn't use it for a polished app. Good luck.

EDIT: I realize the OP wasn't specifically talking about menuitems, but here's a bug report about accelerators and menu items not working so well, just to speak to related bugginess.

[Mono-bugs] [Bug 75996][Maj] New - menuitem event not triggered by Shortcut

Windows.Forms on Mono is so close to working, it's tempting to think it's going to support what you need to get done, but, imo, to consider it solid enough for use beyond making quick utilities would be a mistake.