diff --git a/Source/OpenTK/Platform/Windows/KeyMap.cs b/Source/OpenTK/Platform/Windows/KeyMap.cs new file mode 100644 index 00000000..1fab4464 --- /dev/null +++ b/Source/OpenTK/Platform/Windows/KeyMap.cs @@ -0,0 +1,113 @@ +#region --- License --- +/* Copyright (c) 2007 Stefanos Apostolopoulos + * See license.txt for license information + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using OpenTK.Platform.Windows; +using OpenTK.Input; +using System.Diagnostics; + +namespace OpenTK.Platform.Windows +{ + internal class KeyMap : Dictionary + { + /// + /// Initializes the map between VirtualKeys and OpenTK.Key + /// + internal KeyMap() + { + try + { + this.Add(VirtualKeys.ESCAPE, Key.Escape); + + // Function keys + for (int i = 0; i < 24; i++) + { + this.Add((VirtualKeys)((int)VirtualKeys.F1 + i), Key.F1 + i); + } + + // Number keys (0-9) + for (int i = 0; i <= 9; i++) + { + this.Add((VirtualKeys)(0x30 + i), Key.Number0 + i); + } + + // Letters (A-Z) + for (int i = 0; i < 26; i++) + { + this.Add((VirtualKeys)(0x41 + i), Key.A + i); + } + + this.Add(VirtualKeys.TAB, Key.Tab); + this.Add(VirtualKeys.CAPITAL, Key.CapsLock); + this.Add(VirtualKeys.LCONTROL, Key.ControlLeft); + this.Add(VirtualKeys.LSHIFT, Key.ShiftLeft); + this.Add(VirtualKeys.LWIN, Key.WinLeft); + this.Add(VirtualKeys.LMENU, Key.AltLeft); + this.Add(VirtualKeys.SPACE, Key.Space); + this.Add(VirtualKeys.RMENU, Key.AltRight); + this.Add(VirtualKeys.RWIN, Key.WinRight); + this.Add(VirtualKeys.APPS, Key.Menu); + this.Add(VirtualKeys.RCONTROL, Key.ControlRight); + this.Add(VirtualKeys.RSHIFT, Key.ShiftRight); + this.Add(VirtualKeys.RETURN, Key.Enter); + this.Add(VirtualKeys.BACK, Key.BackSpace); + + this.Add(VirtualKeys.OEM_1, Key.Semicolon); // Varies by keyboard, ;: on Win2K/US + this.Add(VirtualKeys.OEM_2, Key.Slash); // Varies by keyboard, /? on Win2K/US + this.Add(VirtualKeys.OEM_3, Key.Tilde); // Varies by keyboard, `~ on Win2K/US + this.Add(VirtualKeys.OEM_4, Key.BracketLeft); // Varies by keyboard, [{ on Win2K/US + this.Add(VirtualKeys.OEM_5, Key.BackSlash); // Varies by keyboard, \| on Win2K/US + this.Add(VirtualKeys.OEM_6, Key.BracketRight); // Varies by keyboard, ]} on Win2K/US + this.Add(VirtualKeys.OEM_7, Key.Quote); // Varies by keyboard, '" on Win2K/US + this.Add(VirtualKeys.OEM_PLUS, Key.Plus); // Invariant: + + this.Add(VirtualKeys.OEM_COMMA, Key.Comma); // Invariant: , + this.Add(VirtualKeys.OEM_MINUS, Key.Minus); // Invariant: - + this.Add(VirtualKeys.OEM_PERIOD, Key.Period); // Invariant: . + + this.Add(VirtualKeys.HOME, Key.Home); + this.Add(VirtualKeys.END, Key.End); + this.Add(VirtualKeys.DELETE, Key.Delete); + this.Add(VirtualKeys.PRIOR, Key.PageUp); + this.Add(VirtualKeys.NEXT, Key.PageDown); + this.Add(VirtualKeys.PRINT, Key.PrintScreen); + this.Add(VirtualKeys.PAUSE, Key.Pause); + this.Add(VirtualKeys.NUMLOCK, Key.NumLock); + + this.Add(VirtualKeys.SCROLL, Key.ScrollLock); + this.Add(VirtualKeys.SNAPSHOT, Key.PrintScreen); + this.Add(VirtualKeys.CLEAR, Key.Clear); + this.Add(VirtualKeys.INSERT, Key.Insert); + + this.Add(VirtualKeys.SLEEP, Key.Sleep); + + // Keypad + for (int i = 0; i <= 9; i++) + { + this.Add((VirtualKeys)((int)VirtualKeys.NUMPAD0 + i), Key.Keypad0 + i); + } + this.Add(VirtualKeys.DECIMAL, Key.KeypadDecimal); + this.Add(VirtualKeys.ADD, Key.KeypadAdd); + this.Add(VirtualKeys.SUBTRACT, Key.KeypadSubtract); + this.Add(VirtualKeys.DIVIDE, Key.KeypadDivide); + this.Add(VirtualKeys.MULTIPLY, Key.KeypadMultiply); + + // Navigation + this.Add(VirtualKeys.UP, Key.Up); + this.Add(VirtualKeys.DOWN, Key.Down); + this.Add(VirtualKeys.LEFT, Key.Left); + this.Add(VirtualKeys.RIGHT, Key.Right); + } + catch (ArgumentException e) + { + Debug.Print("Exception while creating keymap: '{0}'.", e.ToString()); + System.Windows.Forms.MessageBox.Show( + String.Format("Exception while creating keymap: '{0}'.", e.ToString())); + } + } + } +} diff --git a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs index bf4c607d..9c57b313 100644 --- a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs +++ b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs @@ -23,116 +23,6 @@ namespace OpenTK.Platform.Windows private List keyboards = new List(); private IntPtr window; - #region internal static Dictionary KeyMap - - internal static Dictionary KeyMap = - new Dictionary((int)VirtualKeys.Last); - - private static bool keyMapExists; - /// - /// Initializes the map between VirtualKeys and OpenTK.Key - /// - private static void InitKeyMap() - { - if (!keyMapExists) - { - try - { - KeyMap.Add(VirtualKeys.ESCAPE, Key.Escape); - - // Function keys - for (int i = 0; i < 24; i++) - { - KeyMap.Add((VirtualKeys)((int)VirtualKeys.F1 + i), Key.F1 + i); - } - - // Number keys (0-9) - for (int i = 0; i <= 9; i++) - { - KeyMap.Add((VirtualKeys)(0x30 + i), Key.Number0 + i); - } - - // Letters (A-Z) - for (int i = 0; i < 26; i++) - { - KeyMap.Add((VirtualKeys)(0x41 + i), Key.A + i); - } - - KeyMap.Add(VirtualKeys.TAB, Key.Tab); - KeyMap.Add(VirtualKeys.CAPITAL, Key.CapsLock); - KeyMap.Add(VirtualKeys.LCONTROL, Key.ControlLeft); - KeyMap.Add(VirtualKeys.LSHIFT, Key.ShiftLeft); - KeyMap.Add(VirtualKeys.LWIN, Key.WinLeft); - KeyMap.Add(VirtualKeys.LMENU, Key.AltLeft); - KeyMap.Add(VirtualKeys.SPACE, Key.Space); - KeyMap.Add(VirtualKeys.RMENU, Key.AltRight); - KeyMap.Add(VirtualKeys.RWIN, Key.WinRight); - KeyMap.Add(VirtualKeys.APPS, Key.Menu); - KeyMap.Add(VirtualKeys.RCONTROL, Key.ControlRight); - KeyMap.Add(VirtualKeys.RSHIFT, Key.ShiftRight); - KeyMap.Add(VirtualKeys.RETURN, Key.Enter); - KeyMap.Add(VirtualKeys.BACK, Key.BackSpace); - - KeyMap.Add(VirtualKeys.OEM_1, Key.Semicolon); // Varies by keyboard, ;: on Win2K/US - KeyMap.Add(VirtualKeys.OEM_2, Key.Slash); // Varies by keyboard, /? on Win2K/US - KeyMap.Add(VirtualKeys.OEM_3, Key.Tilde); // Varies by keyboard, `~ on Win2K/US - KeyMap.Add(VirtualKeys.OEM_4, Key.BracketLeft); // Varies by keyboard, [{ on Win2K/US - KeyMap.Add(VirtualKeys.OEM_5, Key.BackSlash); // Varies by keyboard, \| on Win2K/US - KeyMap.Add(VirtualKeys.OEM_6, Key.BracketRight); // Varies by keyboard, ]} on Win2K/US - KeyMap.Add(VirtualKeys.OEM_7, Key.Quote); // Varies by keyboard, '" on Win2K/US - KeyMap.Add(VirtualKeys.OEM_PLUS, Key.Plus); // Invariant: + - KeyMap.Add(VirtualKeys.OEM_COMMA, Key.Comma); // Invariant: , - KeyMap.Add(VirtualKeys.OEM_MINUS, Key.Minus); // Invariant: - - KeyMap.Add(VirtualKeys.OEM_PERIOD, Key.Period); // Invariant: . - - KeyMap.Add(VirtualKeys.HOME, Key.Home); - KeyMap.Add(VirtualKeys.END, Key.End); - KeyMap.Add(VirtualKeys.DELETE, Key.Delete); - KeyMap.Add(VirtualKeys.PRIOR, Key.PageUp); - KeyMap.Add(VirtualKeys.NEXT, Key.PageDown); - KeyMap.Add(VirtualKeys.PRINT, Key.PrintScreen); - KeyMap.Add(VirtualKeys.PAUSE, Key.Pause); - KeyMap.Add(VirtualKeys.NUMLOCK, Key.NumLock); - - KeyMap.Add(VirtualKeys.SCROLL, Key.ScrollLock); - KeyMap.Add(VirtualKeys.SNAPSHOT, Key.PrintScreen); - KeyMap.Add(VirtualKeys.CLEAR, Key.Clear); - KeyMap.Add(VirtualKeys.INSERT, Key.Insert); - - KeyMap.Add(VirtualKeys.SLEEP, Key.Sleep); - - // Keypad - for (int i = 0; i <= 9; i++) - { - KeyMap.Add((VirtualKeys)((int)VirtualKeys.NUMPAD0 + i), Key.Keypad0 + i); - } - KeyMap.Add(VirtualKeys.DECIMAL, Key.KeypadDecimal); - KeyMap.Add(VirtualKeys.ADD, Key.KeypadAdd); - KeyMap.Add(VirtualKeys.SUBTRACT, Key.KeypadSubtract); - KeyMap.Add(VirtualKeys.DIVIDE, Key.KeypadDivide); - KeyMap.Add(VirtualKeys.MULTIPLY, Key.KeypadMultiply); - - // Navigation - KeyMap.Add(VirtualKeys.UP, Key.Up); - KeyMap.Add(VirtualKeys.DOWN, Key.Down); - KeyMap.Add(VirtualKeys.LEFT, Key.Left); - KeyMap.Add(VirtualKeys.RIGHT, Key.Right); - } - catch (ArgumentException e) - { - Debug.Print("Exception while creating keymap: '{0}'.", e.ToString()); - System.Windows.Forms.MessageBox.Show( - String.Format("Exception while creating keymap: '{0}'.", e.ToString())); - } - finally - { - keyMapExists = true; - } - } - } - - #endregion - #region --- Constructors --- internal WinRawKeyboard() @@ -146,7 +36,6 @@ namespace OpenTK.Platform.Windows Debug.Indent(); this.window = windowHandle; - InitKeyMap(); UpdateKeyboardList(); @@ -311,15 +200,12 @@ namespace OpenTK.Platform.Windows return true; default: - if (!WinRawKeyboard.KeyMap.ContainsKey(rin.Data.Keyboard.VKey)) - { + if (!WMInput.KeyMap.ContainsKey(rin.Data.Keyboard.VKey)) Debug.Print("Virtual key {0} ({1}) not mapped.", - rin.Data.Keyboard.VKey, (int)rin.Data.Keyboard.VKey); - } + rin.Data.Keyboard.VKey, (int)rin.Data.Keyboard.VKey); else - { - keyboards[index][WinRawKeyboard.KeyMap[rin.Data.Keyboard.VKey]] = pressed; - } + keyboards[index][WMInput.KeyMap[rin.Data.Keyboard.VKey]] = pressed; + return false; }