Merge pull request #202 from Frassle/issue201

[Input] Legacy keyboard respects the KeyRepeat field.

Fixes #201.
This commit is contained in:
Fraser Waters 2014-11-23 18:15:31 +01:00
commit a43181a802
2 changed files with 20 additions and 38 deletions

View file

@ -70,7 +70,7 @@ namespace Examples.Tests
: base(800, 600, GraphicsMode.Default)
{
VSync = VSyncMode.On;
Keyboard.KeyRepeat = true;
Keyboard.KeyRepeat = false;
KeyDown += KeyDownHandler;
KeyUp += KeyUpHandler;
KeyPress += KeyPressHandler;
@ -159,13 +159,17 @@ namespace Examples.Tests
p = PointToScreen(p);
OpenTK.Input.Mouse.SetPosition(p.X, p.Y);
break;
case Key.R:
Keyboard.KeyRepeat = !Keyboard.KeyRepeat;
break;
}
if (!keyboard_keys.ContainsKey(e.Key))
{
keyboard_keys.Add(e.Key, 0);
}
keyboard_keys[e.Key] = e.IsRepeat ? 1 : 0;
keyboard_keys[e.Key] = keyboard_keys[e.Key] + 1;
keyboard_modifiers = e.Modifiers;
keyboard_state = e.Keyboard;
}
@ -183,7 +187,7 @@ namespace Examples.Tests
{
legacy_keyboard_keys.Add(e.Key, 0);
}
legacy_keyboard_keys[e.Key] = e.IsRepeat ? 1 : 0;
legacy_keyboard_keys[e.Key] = legacy_keyboard_keys[e.Key] + 1;
legacy_keyboard_modifiers = e.Modifiers;
legacy_keyboard_state = e.Keyboard;
}

View file

@ -210,8 +210,16 @@ namespace OpenTK.Input
internal void HandleKeyDown(object sender, KeyboardKeyEventArgs e)
{
state = e.Keyboard;
// KeyRepeat IsRepeat KeyDown
// False False True
// False True False
// True False True
// True True True
if (this.KeyRepeat || !e.IsRepeat)
{
KeyDown(this, e);
}
}
internal void HandleKeyUp(object sender, KeyboardKeyEventArgs e)
{
@ -219,36 +227,6 @@ namespace OpenTK.Input
KeyUp(this, e);
}
#if false
internal void SetKey(Key key, uint scancode, KeyModifiers mods, bool pressed)
{
if (state[key] != pressed || KeyRepeat)
{
// limit scancode to 8bits, otherwise the assignment
// below will crash randomly
scancode &= 0xff;
keys[(int)key] = scancodes[scancode] = state;
if (state && KeyDown != null)
{
args.Key = key;
args.ScanCode = scancode;
args.Modifiers = mods;
KeyDown(this, args);
}
else if (!state && KeyUp != null)
{
args.Key = key;
args.ScanCode = scancode;
args.Modifiers = mods;
KeyUp(this, args);
}
}
}
#endif
#endregion
}
}