[Gtk-sharp-list] Modifier Keys on MacOS X

Jacek Rużyczka stacheldraht at interia.pl
Tue Jun 21 09:20:41 EDT 2011


Hi folks,

as you might know, the Command key (aka apple key or ⌘ key) does what the 
Control key is for on Windows and Linux. My Gtk# sharp app is being developed 
with MonoDevelop on Linux, but is intended to run on Windows and MacOS X as 
well.

When adding an accelerator to a menu item, MonoDevelop generates the following 
code, for example, for a "Select All" menu item activated by typing ^A:

this.AllesMarkieren = new global::Gtk.Action ("AllesMarkieren", 
global::Mono.Unix.Catalog.GetString ("Alles _markieren"), null, null);
this.AllesMarkieren.ShortLabel = "Alles _markieren";
w1.Add (this.AllesMarkieren, "<Control><Mod2>a");

MacOS X users, of course, would wanna use ⌘A, as this is Apple tradition.

Sometimes I would like to "accelerate" an operation, which is not bound to a 
menu item, so I write a KeyPressEvent and KeyReleaseEvent handler like this:

protected virtual void OnKeyPressed (object o, Gtk.KeyPressEventArgs args)
	{
		string key = args.Event.Key.ToString();
			
		if (key == "m" || key == "M") {
			if (this.control) {
				this.assemblyButton.Activate();
			}
		}
		else if (key == "k" || key == "K") {
			if (this.control) {
				this.OnItemCalculationButtonPressed(this, new EventArgs());
			}
		}
		else if (key.StartsWith("Control") || key.StartsWith("Command") || 			
key.StartsWith("Cmd")) {
			this.control = true;
		}
	}

protected virtual void OnKeyReleased (object o, Gtk.KeyReleaseEventArgs args)
	{
		string key = args.Event.Key.ToString();
			
		if (key.StartsWith("Shift")) {
			this.shift = false;
		}
		else if (key.StartsWith("Control") || key.StartsWith("Command") || 
key.StartsWith("Cmd")) {
			this.control = false;
		}
	}

In the hand-made code I've added both Control, and Command keys, but frankly 
speaking, I wanna have all my control sequences activated on Mac with the ⌘ 
key and nothing else.

Now here's my first question: Does Gtk# automatically treat the ⌘ key as the 
MacOS X equivalent to the Ctrl key? And if not: How can I get the menu item 
accelerator (example 1) working on Mac with ⌘ instead of Ctrl?

Second question: I'm also using the Windows key for shortcuts, for instance 
[Win]+[F1]. On Linux the key is recognised as a "Super" key (but on some 
systems it's purportedly called "Meta"). What is the MacOS X equivalent of the 
Windows / Super key then?

Any useful help is greatly appreciated. ^^

Kid regards
Jacek Rużyczka

----------------------------------------------------------------
Najkorzystniejsze oferty domow i mieszkan!
Sprawdz >> http://linkint.pl/f29c9


More information about the Gtk-sharp-list mailing list