Moved KeyMap from WinRawKeyboard to its own class.
This commit is contained in:
parent
22dfa79f08
commit
9a50727029
2 changed files with 117 additions and 118 deletions
113
Source/OpenTK/Platform/Windows/KeyMap.cs
Normal file
113
Source/OpenTK/Platform/Windows/KeyMap.cs
Normal file
|
@ -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<VirtualKeys, Input.Key>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the map between VirtualKeys and OpenTK.Key
|
||||
/// </summary>
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,116 +23,6 @@ namespace OpenTK.Platform.Windows
|
|||
private List<KeyboardDevice> keyboards = new List<KeyboardDevice>();
|
||||
private IntPtr window;
|
||||
|
||||
#region internal static Dictionary<VirtualKeys, Input.Key> KeyMap
|
||||
|
||||
internal static Dictionary<VirtualKeys, Input.Key> KeyMap =
|
||||
new Dictionary<VirtualKeys, Input.Key>((int)VirtualKeys.Last);
|
||||
|
||||
private static bool keyMapExists;
|
||||
/// <summary>
|
||||
/// Initializes the map between VirtualKeys and OpenTK.Key
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue