Permalink
Browse files

Committing artfunkel patch for scan codes

  • Loading branch information...
1 parent d1713ff commit 0f64af130a1c132ae66b1d6e82f7eded92b34827 @andykorth committed Jan 24, 2013
@@ -52,6 +52,7 @@ public static void Main()
// The ExampleBrowser works pretty poorly on some platforms, so you may want to start examples directly.
// for example: Examples.Tutorial.T12_GLSL_Parallax.Main ();
// Examples.Tutorial.T10_GLSL_Cube.Main ();
+ Examples.Tests.BasicMouseInput.Main ();
using (Form browser = new ExampleBrowser())
{
@@ -25,7 +25,7 @@ public class BasicMouseInput : GameWindow
{
public BasicMouseInput()
- : base(800, 600, GraphicsMode.Default)
+ : base(800, 600)
{ }
protected override void OnLoad(EventArgs e)
@@ -42,6 +42,8 @@ protected override void OnLoad(EventArgs e)
protected override void OnUpdateFrame(FrameEventArgs e)
{
+ base.OnUpdateFrame(e);
+
// Here's the big test!
if(OpenTK.Input.Mouse.GetState()[MouseButton.Left]){
Console.WriteLine("The left mouse button is down!");
@@ -66,7 +68,7 @@ protected override void OnUpdateFrame(FrameEventArgs e)
protected override void OnRenderFrame(FrameEventArgs e)
{
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
+ GL.Clear(ClearBufferMask.ColorBufferBit);
SwapBuffers();
}
@@ -78,7 +80,8 @@ public static void Main()
// Get the title and category of this example using reflection.
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
- example.Run(30.0, 0.0);
+
+ example.Run(30.0);
}
}
@@ -22,6 +22,7 @@ public sealed class KeyboardDevice : IInputDevice
{
//private IKeyboard keyboard;
private bool[] keys = new bool[Enum.GetValues(typeof(Key)).Length];
+ private bool[] scancodes = new bool[256];
private string description;
private int numKeys, numFKeys, numLeds;
private IntPtr devID;
@@ -44,24 +45,16 @@ public sealed class KeyboardDevice : IInputDevice
public bool this[Key key]
{
get { return keys[(int)key]; }
- internal set
- {
- if (keys[(int)key] != value || KeyRepeat)
- {
- keys[(int)key] = value;
-
- if (value && KeyDown != null)
- {
- args.Key = key;
- KeyDown(this, args);
- }
- else if (!value && KeyUp != null)
- {
- args.Key = key;
- KeyUp(this, args);
- }
- }
- }
+ }
+
+ /// <summary>
+ /// Gets a value indicating the status of the specified Key.
+ /// </summary>
+ /// <param name="scancode">The scancode to check.</param>
+ /// <returns>True if the scancode is pressed, false otherwise.</returns>
+ public bool this[uint scancode]
+ {
+ get { return scancodes[scancode]; }
}
/// <summary>
@@ -197,12 +190,34 @@ public override string ToString()
internal void ClearKeys()
{
for (int i = 0; i < keys.Length; i++)
- if (this[(Key)i]) // Make sure KeyUp events are *not* raised for keys that are up, even if key repeat is on.
- this[(Key)i] = false;
+ keys[i] = false;
+ for (uint i = 0; i < scancodes.Length; i++)
+ scancodes[i] = false;
}
#endregion
+ internal void SetKey(Key key, uint scancode, bool state)
+ {
+ if (keys[(int)key] != state || KeyRepeat)
+ {
+ keys[(int)key] = scancodes[scancode] = state;
+
+ if (state && KeyDown != null)
+ {
+ args.Key = key;
+ args.ScanCode = scancode;
+ KeyDown(this, args);
+ }
+ else if (!state && KeyUp != null)
+ {
+ args.Key = key;
+ args.ScanCode = scancode;
+ KeyUp(this, args);
+ }
+ }
+ }
+
#endregion
}
}
@@ -1,83 +1,95 @@
-#region License
-//
-// The Open Toolkit Library License
-//
-// Copyright (c) 2006 - 2009 the Open Toolkit library.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do
-// so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenTK.Input
-{
- /// <summary>
- /// Defines the event data for <see cref="KeyboardDevice"/> events.
- /// </summary>
- /// <remarks>
- /// <para>
- /// Do not cache instances of this type outside their event handler.
- /// If necessary, you can clone a KeyboardEventArgs instance using the
- /// <see cref="KeyboardKeyEventArgs(KeyboardKeyEventArgs)"/> constructor.
- /// </para>
- /// </remarks>
- public class KeyboardKeyEventArgs : EventArgs
- {
- #region Fields
-
- Key key;
-
- #endregion
-
- #region Constructors
-
- /// <summary>
- /// Constructs a new KeyboardEventArgs instance.
- /// </summary>
- public KeyboardKeyEventArgs() { }
-
- /// <summary>
- /// Constructs a new KeyboardEventArgs instance.
- /// </summary>
- /// <param name="args">An existing KeyboardEventArgs instance to clone.</param>
- public KeyboardKeyEventArgs(KeyboardKeyEventArgs args)
- {
- Key = args.Key;
- }
-
- #endregion
-
- #region Public Members
-
- /// <summary>
- /// Gets the <see cref="Key"/> that generated this event.
- /// </summary>
- public Key Key
- {
- get { return key; }
- internal set { key = value; }
- }
-
- #endregion
- }
-}
+#region License
+//
+// The Open Toolkit Library License
+//
+// Copyright (c) 2006 - 2009 the Open Toolkit library.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights to
+// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+// the Software, and to permit persons to whom the Software is furnished to do
+// so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenTK.Input
+{
+ /// <summary>
+ /// Defines the event data for <see cref="KeyboardDevice"/> events.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Do not cache instances of this type outside their event handler.
+ /// If necessary, you can clone a KeyboardEventArgs instance using the
+ /// <see cref="KeyboardKeyEventArgs(KeyboardKeyEventArgs)"/> constructor.
+ /// </para>
+ /// </remarks>
+ public class KeyboardKeyEventArgs : EventArgs
+ {
+ #region Fields
+
+ Key key;
+ uint scancode;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Constructs a new KeyboardEventArgs instance.
+ /// </summary>
+ public KeyboardKeyEventArgs() { }
+
+ /// <summary>
+ /// Constructs a new KeyboardEventArgs instance.
+ /// </summary>
+ /// <param name="args">An existing KeyboardEventArgs instance to clone.</param>
+ public KeyboardKeyEventArgs(KeyboardKeyEventArgs args)
+ {
+ Key = args.Key;
+ ScanCode = args.ScanCode;
+ }
+
+ #endregion
+
+ #region Public Members
+
+ /// <summary>
+ /// Gets the <see cref="Key"/> that generated this event.
+ /// </summary>
+ public Key Key
+ {
+ get { return key; }
+ internal set { key = value; }
+ }
+
+ /// <summary>
+ /// Gets the scancode which generated this event.
+ /// </summary>
+ public uint ScanCode
+ {
+ get { return scancode; }
+ internal set { scancode = value; }
+ }
+
+
+ #endregion
+ }
+}
Oops, something went wrong. Retry.

0 comments on commit 0f64af1

Please sign in to comment.