From 8f90c9d50fb9ee02508cdb3b9cb5711b5b26c1b6 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Tue, 31 Jul 2007 21:50:29 +0000 Subject: [PATCH] Added Windows.API.VirtualKeys enum. Started VirtualKeus --> OpenTK.Input.Keys keymap . Removed Keyboard.Key set property. --- Source/Examples/Tutorial/T03_RotatingCube.cs | 6 + Source/OpenTK/Input/IKeyboard.cs | 2 +- Source/OpenTK/Input/Keyboard.cs | 2 +- Source/OpenTK/Platform/Windows/API.cs | 265 +++++++++++++++++- .../OpenTK/Platform/Windows/WinRawKeyboard.cs | 51 +++- 5 files changed, 313 insertions(+), 13 deletions(-) diff --git a/Source/Examples/Tutorial/T03_RotatingCube.cs b/Source/Examples/Tutorial/T03_RotatingCube.cs index bf542c50..b5374f4b 100644 --- a/Source/Examples/Tutorial/T03_RotatingCube.cs +++ b/Source/Examples/Tutorial/T03_RotatingCube.cs @@ -86,6 +86,12 @@ namespace Examples.Tutorial return; } + if ((Key[OpenTK.Input.Keys.LeftAlt] || Key[OpenTK.Input.Keys.RightAlt]) && + Key[OpenTK.Input.Keys.Enter]) + { + Fullscreen = true; + } + GL.MatrixMode(Enums.MatrixMode.MODELVIEW); GL.LoadIdentity(); Glu.LookAt( diff --git a/Source/OpenTK/Input/IKeyboard.cs b/Source/OpenTK/Input/IKeyboard.cs index 92fb1ac8..f2d3160a 100644 --- a/Source/OpenTK/Input/IKeyboard.cs +++ b/Source/OpenTK/Input/IKeyboard.cs @@ -8,7 +8,7 @@ namespace OpenTK.Input { public interface IKeyboard { - bool this[Keys k] { get; set; } + bool this[Keys k] { get; } //void Poll(); } } diff --git a/Source/OpenTK/Input/Keyboard.cs b/Source/OpenTK/Input/Keyboard.cs index bf4b04b8..69d413ed 100644 --- a/Source/OpenTK/Input/Keyboard.cs +++ b/Source/OpenTK/Input/Keyboard.cs @@ -41,7 +41,7 @@ namespace OpenTK.Input public bool this[Keys k] { get { return keyboard[k]; } - set { keyboard[k] = value; } + //set { keyboard[k] = value; } } #endregion diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index ef17f13a..70c0ffd1 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -1471,7 +1471,8 @@ namespace OpenTK.Platform.Windows /// /// Microsoft Windows message compatible virtual-key code. For more information, see Virtual-Key Codes. /// - public USHORT VKey; + //public USHORT VKey; + public VirtualKeys VKey; /// /// Corresponding window message, for example WM_KEYDOWN, WM_SYSKEYDOWN, and so forth. /// @@ -1906,6 +1907,268 @@ namespace OpenTK.Platform.Windows #endregion + #region VirtualKeys + + public enum VirtualKeys : short + { + /* + * Virtual Keys, Standard Set + */ + LBUTTON = 0x01, + RBUTTON = 0x02, + CANCEL = 0x03, + MBUTTON = 0x04, /* NOT contiguous with L & RBUTTON */ + + XBUTTON1 = 0x05, /* NOT contiguous with L & RBUTTON */ + XBUTTON2 = 0x06, /* NOT contiguous with L & RBUTTON */ + + /* + * 0x07 : unassigned + */ + + BACK = 0x08, + TAB = 0x09, + + /* + * 0x0A - 0x0B : reserved + */ + + CLEAR = 0x0C, + RETURN = 0x0D, + + SHIFT = 0x10, + CONTROL = 0x11, + MENU = 0x12, + PAUSE = 0x13, + CAPITAL = 0x14, + + KANA = 0x15, + HANGEUL = 0x15, /* old name - should be here for compatibility */ + HANGUL = 0x15, + JUNJA = 0x17, + FINAL = 0x18, + HANJA = 0x19, + KANJI = 0x19, + + ESCAPE = 0x1B, + + CONVERT = 0x1C, + NONCONVERT = 0x1D, + ACCEPT = 0x1E, + MODECHANGE = 0x1F, + + SPACE = 0x20, + PRIOR = 0x21, + NEXT = 0x22, + END = 0x23, + HOME = 0x24, + LEFT = 0x25, + UP = 0x26, + RIGHT = 0x27, + DOWN = 0x28, + SELECT = 0x29, + PRINT = 0x2A, + EXECUTE = 0x2B, + SNAPSHOT = 0x2C, + INSERT = 0x2D, + DELETE = 0x2E, + HELP = 0x2F, + + /* + * 0 - 9 are the same as ASCII '0' - '9' (0x30 - 0x39) + * 0x40 : unassigned + * A - Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A) + */ + + LWIN = 0x5B, + RWIN = 0x5C, + APPS = 0x5D, + + /* + * 0x5E : reserved + */ + + SLEEP = 0x5F, + + NUMPAD0 = 0x60, + NUMPAD1 = 0x61, + NUMPAD2 = 0x62, + NUMPAD3 = 0x63, + NUMPAD4 = 0x64, + NUMPAD5 = 0x65, + NUMPAD6 = 0x66, + NUMPAD7 = 0x67, + NUMPAD8 = 0x68, + NUMPAD9 = 0x69, + MULTIPLY = 0x6A, + ADD = 0x6B, + SEPARATOR = 0x6C, + SUBTRACT = 0x6D, + DECIMAL = 0x6E, + DIVIDE = 0x6F, + F1 = 0x70, + F2 = 0x71, + F3 = 0x72, + F4 = 0x73, + F5 = 0x74, + F6 = 0x75, + F7 = 0x76, + F8 = 0x77, + F9 = 0x78, + F10 = 0x79, + F11 = 0x7A, + F12 = 0x7B, + F13 = 0x7C, + F14 = 0x7D, + F15 = 0x7E, + F16 = 0x7F, + F17 = 0x80, + F18 = 0x81, + F19 = 0x82, + F20 = 0x83, + F21 = 0x84, + F22 = 0x85, + F23 = 0x86, + F24 = 0x87, + + /* + * 0x88 - 0x8F : unassigned + */ + + NUMLOCK = 0x90, + SCROLL = 0x91, + + /* + * NEC PC-9800 kbd definitions + */ + OEM_NEC_EQUAL= 0x92, // '=' key on numpad + + /* + * Fujitsu/OASYS kbd definitions + */ + OEM_FJ_JISHO = 0x92, // 'Dictionary' key + OEM_FJ_MASSHOU = 0x93, // 'Unregister word' key + OEM_FJ_TOUROKU = 0x94, // 'Register word' key + OEM_FJ_LOYA = 0x95, // 'Left OYAYUBI' key + OEM_FJ_ROYA = 0x96, // 'Right OYAYUBI' key + + /* + * 0x97 - 0x9F : unassigned + */ + + /* + * L* & R* - left and right Alt, Ctrl and Shift virtual keys. + * Used only as parameters to GetAsyncKeyState() and GetKeyState(). + * No other API or message will distinguish left and right keys in this way. + */ + LSHIFT = 0xA0, + RSHIFT = 0xA1, + LCONTROL = 0xA2, + RCONTROL = 0xA3, + LMENU = 0xA4, + RMENU = 0xA5, + + BROWSER_BACK = 0xA6, + BROWSER_FORWARD = 0xA7, + BROWSER_REFRESH = 0xA8, + BROWSER_STOP = 0xA9, + BROWSER_SEARCH = 0xAA, + BROWSER_FAVORITES = 0xAB, + BROWSER_HOME = 0xAC, + + VOLUME_MUTE = 0xAD, + VOLUME_DOWN = 0xAE, + VOLUME_UP = 0xAF, + MEDIA_NEXT_TRACK = 0xB0, + MEDIA_PREV_TRACK = 0xB1, + MEDIA_STOP = 0xB2, + MEDIA_PLAY_PAUSE = 0xB3, + LAUNCH_MAIL = 0xB4, + LAUNCH_MEDIA_SELECT = 0xB5, + LAUNCH_APP1 = 0xB6, + LAUNCH_APP2 = 0xB7, + + /* + * 0xB8 - 0xB9 : reserved + */ + + OEM_1 = 0xBA, // ';:' for US + OEM_PLUS = 0xBB, // '+' any country + OEM_COMMA = 0xBC, // ',' any country + OEM_MINUS = 0xBD, // '-' any country + OEM_PERIOD = 0xBE, // '.' any country + OEM_2 = 0xBF, // '/?' for US + OEM_3 = 0xC0, // '`~' for US + + /* + * 0xC1 - 0xD7 : reserved + */ + + /* + * 0xD8 - 0xDA : unassigned + */ + + OEM_4 = 0xDB, // '[{' for US + OEM_5 = 0xDC, // '\|' for US + OEM_6 = 0xDD, // ']}' for US + OEM_7 = 0xDE, // ''"' for US + OEM_8 = 0xDF, + + /* + * 0xE0 : reserved + */ + + /* + * Various extended or enhanced keyboards + */ + OEM_AX = 0xE1, // 'AX' key on Japanese AX kbd + OEM_102 = 0xE2, // "<>" or "\|" on RT 102-key kbd. + ICO_HELP = 0xE3, // Help key on ICO + ICO_00 = 0xE4, // 00 key on ICO + + PROCESSKEY = 0xE5, + + ICO_CLEAR = 0xE6, + + + PACKET = 0xE7, + + /* + * 0xE8 : unassigned + */ + + /* + * Nokia/Ericsson definitions + */ + OEM_RESET = 0xE9, + OEM_JUMP = 0xEA, + OEM_PA1 = 0xEB, + OEM_PA2 = 0xEC, + OEM_PA3 = 0xED, + OEM_WSCTRL = 0xEE, + OEM_CUSEL = 0xEF, + OEM_ATTN = 0xF0, + OEM_FINISH = 0xF1, + OEM_COPY = 0xF2, + OEM_AUTO = 0xF3, + OEM_ENLW = 0xF4, + OEM_BACKTAB = 0xF5, + + ATTN = 0xF6, + CRSEL = 0xF7, + EXSEL = 0xF8, + EREOF = 0xF9, + PLAY = 0xFA, + ZOOM = 0xFB, + NONAME = 0xFC, + PA1 = 0xFD, + OEM_CLEAR = 0xFE, + + Last + } + + #endregion + #endregion #region --- Callbacks --- diff --git a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs index a079366b..d7cccea8 100644 --- a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs +++ b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs @@ -47,32 +47,63 @@ namespace OpenTK.Platform.Windows rid[0].ToString()) ); } + + // Set the VirtualKey -> OpenTK.Key map + keyMap.Add(API.VirtualKeys.ESCAPE, Keys.Escape); + keyMap.Add(API.VirtualKeys.F1, Keys.F1); + keyMap.Add(API.VirtualKeys.F2, Keys.F2); + keyMap.Add(API.VirtualKeys.F3, Keys.F3); + keyMap.Add(API.VirtualKeys.F4, Keys.F4); + keyMap.Add(API.VirtualKeys.F5, Keys.F5); + keyMap.Add(API.VirtualKeys.F6, Keys.F6); + keyMap.Add(API.VirtualKeys.F7, Keys.F7); + keyMap.Add(API.VirtualKeys.F8, Keys.F8); + keyMap.Add(API.VirtualKeys.F9, Keys.F9); + keyMap.Add(API.VirtualKeys.F10, Keys.F10); + keyMap.Add(API.VirtualKeys.F11, Keys.F11); + keyMap.Add(API.VirtualKeys.F12, Keys.F12); } internal bool ProcessEvent(API.RawInput rin) { - if (rin.Data.Keyboard.VKey == API.Constants.VK_ESCAPE) + switch (rin.Header.Type) { - if (rin.Data.Keyboard.Message == API.Constants.WM_KEYDOWN) - keys[(int)Keys.Escape] = true; - else - keys[(int)Keys.Escape] = false; - - return true; + case API.RawInputDeviceType.KEYBOARD: + this[keyMap[rin.Data.Keyboard.VKey]] = + rin.Data.Keyboard.Message == API.Constants.WM_KEYDOWN || + rin.Data.Keyboard.Message == API.Constants.WM_SYSKEYDOWN; + break; } return false; } + #region KeyMap + + internal static Dictionary keyMap = + new Dictionary((int)API.VirtualKeys.Last); + + /* + internal static List> keyMap = + new List>( + new KeyValuePair[] + { + new KeyValuePair(API.VirtualKeys.ESCAPE, Keys.Escape), + new KeyValuePair(API.VirtualKeys.F1, Keys.F1) + } + ); + */ + #endregion + #region --- IKeyboard members --- public bool this[Keys k] { get { return keys[(int)k]; } - set + internal set { - /*keys[(int)k] = value;*/ - throw new NotImplementedException(); + keys[(int)k] = value; + //throw new NotImplementedException(); } }