From 5b3c08f463e2f90dc96fa43fdfdc2f64041eaa26 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Tue, 30 Nov 2010 23:22:56 +0000 Subject: [PATCH] * Platform/MacOS/CarbonGLNative.cs: Fixed handling of key repeat. Fixed crash when unknown key is pressed. --- .../OpenTK/Platform/MacOS/CarbonGLNative.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs index 7c85b7c8..c1c8eaa5 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -369,25 +369,37 @@ namespace OpenTK.Platform.MacOS switch (evt.KeyboardEventKind) { case KeyboardEventKind.RawKeyRepeat: - InputDriver.Keyboard[0].KeyRepeat = true; - goto case KeyboardEventKind.RawKeyDown; + if (InputDriver.Keyboard[0].KeyRepeat) + goto case KeyboardEventKind.RawKeyDown; + break; case KeyboardEventKind.RawKeyDown: - OnKeyPress(mKeyPressArgs); - InputDriver.Keyboard[0][Keymap[code]] = true; + { + OpenTK.Input.Key key; + if (Keymap.TryGetValue(code, out key)) + { + InputDriver.Keyboard[0][key] = true; + OnKeyPress(mKeyPressArgs); + } return OSStatus.NoError; + } case KeyboardEventKind.RawKeyUp: - InputDriver.Keyboard[0][Keymap[code]] = false; + { + OpenTK.Input.Key key; + if (Keymap.TryGetValue(code, out key)) + { + InputDriver.Keyboard[0][key] = false; + } return OSStatus.NoError; + } case KeyboardEventKind.RawKeyModifiersChanged: ProcessModifierKey(inEvent); return OSStatus.NoError; - - default: - return OSStatus.EventNotHandled; } + + return OSStatus.EventNotHandled; } private OSStatus ProcessWindowEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)