mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 17:25:39 +00:00
[Mac] Optimized MacOSKeyCode translation
This also reduces memory allocations on startup by ~10K.
This commit is contained in:
parent
4ae65c86ff
commit
9f39aa1b88
1143
Source/OpenTK/Platform/MacOS/CarbonGLNative.cs
Normal file
1143
Source/OpenTK/Platform/MacOS/CarbonGLNative.cs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -36,127 +36,229 @@ namespace OpenTK.Platform.MacOS
|
|||
using Carbon;
|
||||
using Input;
|
||||
|
||||
class MacOSKeyMap : Dictionary<MacOSKeyCode, Key>
|
||||
class MacOSKeyMap
|
||||
{
|
||||
public MacOSKeyMap()
|
||||
public static Key GetKey(MacOSKeyCode code)
|
||||
{
|
||||
// comments indicate members of the Key enum that are missing
|
||||
|
||||
Add(MacOSKeyCode.A, Key.A);
|
||||
Add(MacOSKeyCode.OptionAlt, Key.AltLeft);
|
||||
// AltRight
|
||||
Add(MacOSKeyCode.B, Key.B);
|
||||
|
||||
Add(MacOSKeyCode.Backslash, Key.BackSlash);
|
||||
Add(MacOSKeyCode.Backspace, Key.BackSpace);
|
||||
Add(MacOSKeyCode.BracketLeft, Key.BracketLeft);
|
||||
Add(MacOSKeyCode.BracketRight, Key.BracketRight);
|
||||
Add(MacOSKeyCode.C, Key.C);
|
||||
// Capslock
|
||||
// Clear
|
||||
Add(MacOSKeyCode.Comma, Key.Comma);
|
||||
Add(MacOSKeyCode.Control, Key.ControlLeft);
|
||||
// ControlRight
|
||||
Add(MacOSKeyCode.D, Key.D);
|
||||
Add(MacOSKeyCode.Del, Key.Delete);
|
||||
Add(MacOSKeyCode.Down, Key.Down);
|
||||
Add(MacOSKeyCode.E, Key.E);
|
||||
Add(MacOSKeyCode.End, Key.End);
|
||||
Add(MacOSKeyCode.Enter, Key.Enter);
|
||||
Add(MacOSKeyCode.Return, Key.Enter);
|
||||
Add(MacOSKeyCode.Esc, Key.Escape);
|
||||
Add(MacOSKeyCode.F, Key.F);
|
||||
Add(MacOSKeyCode.F1, Key.F1);
|
||||
Add(MacOSKeyCode.F2, Key.F2);
|
||||
Add(MacOSKeyCode.F3, Key.F3);
|
||||
Add(MacOSKeyCode.F4, Key.F4);
|
||||
Add(MacOSKeyCode.F5, Key.F5);
|
||||
Add(MacOSKeyCode.F6, Key.F6);
|
||||
Add(MacOSKeyCode.F7, Key.F7);
|
||||
Add(MacOSKeyCode.F8, Key.F8);
|
||||
Add(MacOSKeyCode.F9, Key.F9);
|
||||
Add(MacOSKeyCode.F10, Key.F10);
|
||||
Add(MacOSKeyCode.F11, Key.F11);
|
||||
Add(MacOSKeyCode.F12, Key.F12);
|
||||
Add(MacOSKeyCode.F13, Key.F13);
|
||||
Add(MacOSKeyCode.F14, Key.F14);
|
||||
Add(MacOSKeyCode.F15, Key.F15);
|
||||
// F16-F35
|
||||
Add(MacOSKeyCode.G, Key.G);
|
||||
Add(MacOSKeyCode.H, Key.H);
|
||||
Add(MacOSKeyCode.Home, Key.Home);
|
||||
Add(MacOSKeyCode.I, Key.I);
|
||||
Add(MacOSKeyCode.Insert, Key.Insert);
|
||||
Add(MacOSKeyCode.J, Key.J);
|
||||
Add(MacOSKeyCode.K, Key.K);
|
||||
Add(MacOSKeyCode.KeyPad_0, Key.Keypad0);
|
||||
Add(MacOSKeyCode.KeyPad_1, Key.Keypad1);
|
||||
Add(MacOSKeyCode.KeyPad_2, Key.Keypad2);
|
||||
Add(MacOSKeyCode.KeyPad_3, Key.Keypad3);
|
||||
Add(MacOSKeyCode.KeyPad_4, Key.Keypad4);
|
||||
Add(MacOSKeyCode.KeyPad_5, Key.Keypad5);
|
||||
Add(MacOSKeyCode.KeyPad_6, Key.Keypad6);
|
||||
Add(MacOSKeyCode.KeyPad_7, Key.Keypad7);
|
||||
Add(MacOSKeyCode.KeyPad_8, Key.Keypad8);
|
||||
Add(MacOSKeyCode.KeyPad_9, Key.Keypad9);
|
||||
Add(MacOSKeyCode.KeyPad_Add, Key.KeypadAdd);
|
||||
Add(MacOSKeyCode.KeyPad_Decimal, Key.KeypadDecimal);
|
||||
Add(MacOSKeyCode.KeyPad_Divide, Key.KeypadDivide);
|
||||
Add(MacOSKeyCode.KeyPad_Enter, Key.KeypadEnter);
|
||||
Add(MacOSKeyCode.KeyPad_Multiply, Key.KeypadMultiply);
|
||||
Add(MacOSKeyCode.KeyPad_Subtract, Key.KeypadSubtract);
|
||||
//Add(MacOSKeyCode.KeyPad_Equal);
|
||||
Add(MacOSKeyCode.L, Key.L);
|
||||
Add(MacOSKeyCode.Left, Key.Left);
|
||||
Add(MacOSKeyCode.M, Key.M);
|
||||
//Key.MaxKeys
|
||||
Add(MacOSKeyCode.Menu, Key.Menu);
|
||||
Add(MacOSKeyCode.Minus, Key.Minus);
|
||||
Add(MacOSKeyCode.N, Key.N);
|
||||
Add(MacOSKeyCode.Key_0, Key.Number0);
|
||||
Add(MacOSKeyCode.Key_1, Key.Number1);
|
||||
Add(MacOSKeyCode.Key_2, Key.Number2);
|
||||
Add(MacOSKeyCode.Key_3, Key.Number3);
|
||||
Add(MacOSKeyCode.Key_4, Key.Number4);
|
||||
Add(MacOSKeyCode.Key_5, Key.Number5);
|
||||
Add(MacOSKeyCode.Key_6, Key.Number6);
|
||||
Add(MacOSKeyCode.Key_7, Key.Number7);
|
||||
Add(MacOSKeyCode.Key_8, Key.Number8);
|
||||
Add(MacOSKeyCode.Key_9, Key.Number9);
|
||||
// Numlock
|
||||
Add(MacOSKeyCode.O, Key.O);
|
||||
Add(MacOSKeyCode.P, Key.P);
|
||||
Add(MacOSKeyCode.Pagedown, Key.PageDown);
|
||||
Add(MacOSKeyCode.Pageup, Key.PageUp);
|
||||
// Pause
|
||||
Add(MacOSKeyCode.Period, Key.Period);
|
||||
Add(MacOSKeyCode.Equals, Key.Plus);
|
||||
// PrintScreen
|
||||
Add(MacOSKeyCode.Q, Key.Q);
|
||||
Add(MacOSKeyCode.Quote, Key.Quote);
|
||||
Add(MacOSKeyCode.R, Key.R);
|
||||
Add(MacOSKeyCode.Right, Key.Right);
|
||||
Add(MacOSKeyCode.S, Key.S);
|
||||
// ScrollLock
|
||||
Add(MacOSKeyCode.Semicolon, Key.Semicolon);
|
||||
Add(MacOSKeyCode.Shift, Key.ShiftLeft);
|
||||
//Key.ShiftRight
|
||||
Add(MacOSKeyCode.Slash, Key.Slash);
|
||||
// Key.Sleep
|
||||
Add(MacOSKeyCode.Space, Key.Space);
|
||||
Add(MacOSKeyCode.T, Key.T);
|
||||
Add(MacOSKeyCode.Tab, Key.Tab);
|
||||
Add(MacOSKeyCode.Tilde, Key.Tilde);
|
||||
Add(MacOSKeyCode.U, Key.U);
|
||||
Add(MacOSKeyCode.Up, Key.Up);
|
||||
Add(MacOSKeyCode.V, Key.V);
|
||||
Add(MacOSKeyCode.W, Key.W);
|
||||
Add(MacOSKeyCode.Command, Key.WinLeft);
|
||||
// WinKeyRight
|
||||
Add(MacOSKeyCode.X, Key.X);
|
||||
Add(MacOSKeyCode.Y, Key.Y);
|
||||
Add(MacOSKeyCode.Z, Key.Z);
|
||||
|
||||
switch (code)
|
||||
{
|
||||
case MacOSKeyCode.A:
|
||||
return Key.A;
|
||||
case MacOSKeyCode.OptionAlt:
|
||||
return Key.AltLeft;
|
||||
// AltRight
|
||||
case MacOSKeyCode.B:
|
||||
return Key.B;
|
||||
case MacOSKeyCode.Backslash:
|
||||
return Key.BackSlash;
|
||||
case MacOSKeyCode.Backspace:
|
||||
return Key.BackSpace;
|
||||
case MacOSKeyCode.BracketLeft:
|
||||
return Key.BracketLeft;
|
||||
case MacOSKeyCode.BracketRight:
|
||||
return Key.BracketRight;
|
||||
case MacOSKeyCode.C:
|
||||
return Key.C;
|
||||
// Capslock
|
||||
// Clear
|
||||
case MacOSKeyCode.Comma:
|
||||
return Key.Comma;
|
||||
case MacOSKeyCode.Control:
|
||||
return Key.ControlLeft;
|
||||
// ControlRight
|
||||
case MacOSKeyCode.D:
|
||||
return Key.D;
|
||||
case MacOSKeyCode.Del:
|
||||
return Key.Delete;
|
||||
case MacOSKeyCode.Down:
|
||||
return Key.Down;
|
||||
case MacOSKeyCode.E:
|
||||
return Key.E;
|
||||
case MacOSKeyCode.End:
|
||||
return Key.End;
|
||||
case MacOSKeyCode.Enter:
|
||||
return Key.Enter;
|
||||
case MacOSKeyCode.Return:
|
||||
return Key.Enter;
|
||||
case MacOSKeyCode.Esc:
|
||||
return Key.Escape;
|
||||
case MacOSKeyCode.F:
|
||||
return Key.F;
|
||||
case MacOSKeyCode.F1:
|
||||
return Key.F1;
|
||||
case MacOSKeyCode.F2:
|
||||
return Key.F2;
|
||||
case MacOSKeyCode.F3:
|
||||
return Key.F3;
|
||||
case MacOSKeyCode.F4:
|
||||
return Key.F4;
|
||||
case MacOSKeyCode.F5:
|
||||
return Key.F5;
|
||||
case MacOSKeyCode.F6:
|
||||
return Key.F6;
|
||||
case MacOSKeyCode.F7:
|
||||
return Key.F7;
|
||||
case MacOSKeyCode.F8:
|
||||
return Key.F8;
|
||||
case MacOSKeyCode.F9:
|
||||
return Key.F9;
|
||||
case MacOSKeyCode.F10:
|
||||
return Key.F10;
|
||||
case MacOSKeyCode.F11:
|
||||
return Key.F11;
|
||||
case MacOSKeyCode.F12:
|
||||
return Key.F12;
|
||||
case MacOSKeyCode.F13:
|
||||
return Key.F13;
|
||||
case MacOSKeyCode.F14:
|
||||
return Key.F14;
|
||||
case MacOSKeyCode.F15:
|
||||
return Key.F15;
|
||||
// F16-F35
|
||||
case MacOSKeyCode.G:
|
||||
return Key.G;
|
||||
case MacOSKeyCode.H:
|
||||
return Key.H;
|
||||
case MacOSKeyCode.Home:
|
||||
return Key.Home;
|
||||
case MacOSKeyCode.I:
|
||||
return Key.I;
|
||||
case MacOSKeyCode.Insert:
|
||||
return Key.Insert;
|
||||
case MacOSKeyCode.J:
|
||||
return Key.J;
|
||||
case MacOSKeyCode.K:
|
||||
return Key.K;
|
||||
case MacOSKeyCode.KeyPad_0:
|
||||
return Key.Keypad0;
|
||||
case MacOSKeyCode.KeyPad_1:
|
||||
return Key.Keypad1;
|
||||
case MacOSKeyCode.KeyPad_2:
|
||||
return Key.Keypad2;
|
||||
case MacOSKeyCode.KeyPad_3:
|
||||
return Key.Keypad3;
|
||||
case MacOSKeyCode.KeyPad_4:
|
||||
return Key.Keypad4;
|
||||
case MacOSKeyCode.KeyPad_5:
|
||||
return Key.Keypad5;
|
||||
case MacOSKeyCode.KeyPad_6:
|
||||
return Key.Keypad6;
|
||||
case MacOSKeyCode.KeyPad_7:
|
||||
return Key.Keypad7;
|
||||
case MacOSKeyCode.KeyPad_8:
|
||||
return Key.Keypad8;
|
||||
case MacOSKeyCode.KeyPad_9:
|
||||
return Key.Keypad9;
|
||||
case MacOSKeyCode.KeyPad_Add:
|
||||
return Key.KeypadAdd;
|
||||
case MacOSKeyCode.KeyPad_Decimal:
|
||||
return Key.KeypadDecimal;
|
||||
case MacOSKeyCode.KeyPad_Divide:
|
||||
return Key.KeypadDivide;
|
||||
case MacOSKeyCode.KeyPad_Enter:
|
||||
return Key.KeypadEnter;
|
||||
case MacOSKeyCode.KeyPad_Multiply:
|
||||
return Key.KeypadMultiply;
|
||||
case MacOSKeyCode.KeyPad_Subtract:
|
||||
return Key.KeypadSubtract;
|
||||
//case MacOSKeyCode.KeyPad_Equal;
|
||||
case MacOSKeyCode.L:
|
||||
return Key.L;
|
||||
case MacOSKeyCode.Left:
|
||||
return Key.Left;
|
||||
case MacOSKeyCode.M:
|
||||
return Key.M;
|
||||
//Key.MaxKeys
|
||||
case MacOSKeyCode.Menu:
|
||||
return Key.Menu;
|
||||
case MacOSKeyCode.Minus:
|
||||
return Key.Minus;
|
||||
case MacOSKeyCode.N:
|
||||
return Key.N;
|
||||
case MacOSKeyCode.Key_0:
|
||||
return Key.Number0;
|
||||
case MacOSKeyCode.Key_1:
|
||||
return Key.Number1;
|
||||
case MacOSKeyCode.Key_2:
|
||||
return Key.Number2;
|
||||
case MacOSKeyCode.Key_3:
|
||||
return Key.Number3;
|
||||
case MacOSKeyCode.Key_4:
|
||||
return Key.Number4;
|
||||
case MacOSKeyCode.Key_5:
|
||||
return Key.Number5;
|
||||
case MacOSKeyCode.Key_6:
|
||||
return Key.Number6;
|
||||
case MacOSKeyCode.Key_7:
|
||||
return Key.Number7;
|
||||
case MacOSKeyCode.Key_8:
|
||||
return Key.Number8;
|
||||
case MacOSKeyCode.Key_9:
|
||||
return Key.Number9;
|
||||
// Numlock
|
||||
case MacOSKeyCode.O:
|
||||
return Key.O;
|
||||
case MacOSKeyCode.P:
|
||||
return Key.P;
|
||||
case MacOSKeyCode.Pagedown:
|
||||
return Key.PageDown;
|
||||
case MacOSKeyCode.Pageup:
|
||||
return Key.PageUp;
|
||||
// Pause
|
||||
case MacOSKeyCode.Period:
|
||||
return Key.Period;
|
||||
case MacOSKeyCode.Equals:
|
||||
return Key.Plus;
|
||||
// PrintScreen
|
||||
case MacOSKeyCode.Q:
|
||||
return Key.Q;
|
||||
case MacOSKeyCode.Quote:
|
||||
return Key.Quote;
|
||||
case MacOSKeyCode.R:
|
||||
return Key.R;
|
||||
case MacOSKeyCode.Right:
|
||||
return Key.Right;
|
||||
case MacOSKeyCode.S:
|
||||
return Key.S;
|
||||
// ScrollLock
|
||||
case MacOSKeyCode.Semicolon:
|
||||
return Key.Semicolon;
|
||||
case MacOSKeyCode.Shift:
|
||||
return Key.ShiftLeft;
|
||||
//Key.ShiftRight
|
||||
case MacOSKeyCode.Slash:
|
||||
return Key.Slash;
|
||||
// Key.Sleep
|
||||
case MacOSKeyCode.Space:
|
||||
return Key.Space;
|
||||
case MacOSKeyCode.T:
|
||||
return Key.T;
|
||||
case MacOSKeyCode.Tab:
|
||||
return Key.Tab;
|
||||
case MacOSKeyCode.Tilde:
|
||||
return Key.Tilde;
|
||||
case MacOSKeyCode.U:
|
||||
return Key.U;
|
||||
case MacOSKeyCode.Up:
|
||||
return Key.Up;
|
||||
case MacOSKeyCode.V:
|
||||
return Key.V;
|
||||
case MacOSKeyCode.W:
|
||||
return Key.W;
|
||||
case MacOSKeyCode.Command:
|
||||
return Key.WinLeft;
|
||||
// WinKeyRight
|
||||
case MacOSKeyCode.X:
|
||||
return Key.X;
|
||||
case MacOSKeyCode.Y:
|
||||
return Key.Y;
|
||||
case MacOSKeyCode.Z:
|
||||
return Key.Z;
|
||||
|
||||
default:
|
||||
return Key.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue