Hotkaces

27 08 2013

Alright, finally got tired of Unity’s way of adding shortcut keys to their menu item tags (I really wish those tags were extensible, seriously). So I wrote a little class to contains all possible permutations. Not the most elegant solution, wish I could have generated these automatically (well I sort of did with some copy/paste/replace magic), but the result is useful and used quite a lot.

Still haven’t solved the issue with detecting the same shortcut used twice but I think it’s possible using this system.

So without further fluff and stuff here’s my solution;

public static class Hotkey
{
  public static class Alt
  {
    public const string Key = " &";
    public const string A = Key + "a";
    public const string B = Key + "b";
    public const string C = Key + "c";
    public const string D = Key + "d";
    public const string E = Key + "e";
    public const string F = Key + "f";
    public const string G = Key + "g";
    public const string H = Key + "h";
    public const string I = Key + "i";
    public const string J = Key + "j";
    public const string K = Key + "k";
    public const string L = Key + "l";
    public const string M = Key + "m";
    public const string N = Key + "n";
    public const string O = Key + "o";
    public const string P = Key + "p";
    public const string Q = Key + "q";
    public const string R = Key + "r";
    public const string S = Key + "s";
    public const string T = Key + "t";
    public const string U = Key + "u";
    public const string V = Key + "v";
    public const string W = Key + "w";
    public const string X = Key + "x";
    public const string Y = Key + "y";
    public const string Z = Key + "z";
 }
}

Rinse and repeat for Ctrl, Shift, ShiftAlt, ShiftCtrl, CtrlAlt, CtrlAltShift.

One final thing to notice, for those of us that haven’t gone googly eyed from the wall of text and have scrolled down to the bottom of the post. I’ve put a single space as a prefix to the .Key string element. Now we can simply write:

[MenuItem("Name/Action" + Hotkey.Alt.Z)

And be done with it.

“You can roam the streets a King whilst everyone’s asleep”

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: