Platform independent keyboard modifiers for shortcuts

I’m implementing keyboard shortcuts in an editor window and was wondering if there’s a standard way to get platform independent modifier keys. For example, keyboard shortcuts use Control on a PC and Command on a Mac.

Right now I use a small utility function:

public static bool CommandKeyDown()
{
	if (Application.platform == RuntimePlatform.OSXEditor)
	{
		return Event.current.command;
	}
	return Event.current.control;
}

But it seems like Unity would have some built in way to handle this kind of thing…? Obviously not urgent since I have a workaround, but would like to tidy this up if possible.

Actually found the exact thing I was looking for: EditorGUI.actionKey

"Is the platform-dependent “action” modifier key held down? (Read Only)

The key is Command on Mac OS X, Control on Windows."

http://unity3d.com/support/documentation/ScriptReference/EditorGUI-actionKey.html

Ok it’s quite common that the equivalent on mac for the control key is the command key but that’s not really a rule or standard. Event.current.command also works on windows machines but it’s the windows key. I don’t see any reason why unity should provide a function that will do exactly what you did.

Actually you aren’t talking to unity here :wink: We are the community that is using Unity. If you have a feature request for Unity post it on feedback.unity3d.com

There isn’t any built-in way, no. After all, Event.current.control exists on OS X as well, whereas there is no real equivalent to the Command key on Windows (I understand the Windows key can’t really be used in the same way). I don’t see anything untidy about your function.