mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 18:45:34 +00:00
Merge pull request #202 from Frassle/issue201
[Input] Legacy keyboard respects the KeyRepeat field. Fixes #201.
This commit is contained in:
commit
a43181a802
|
@ -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,22 +159,26 @@ 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;
|
||||
}
|
||||
|
||||
void KeyUpHandler(object sender, KeyboardKeyEventArgs e)
|
||||
{
|
||||
keyboard_keys.Remove(e.Key);
|
||||
keyboard_modifiers = e.Modifiers;
|
||||
keyboard_state = e.Keyboard;
|
||||
keyboard_keys.Remove(e.Key);
|
||||
keyboard_modifiers = e.Modifiers;
|
||||
keyboard_state = e.Keyboard;
|
||||
}
|
||||
|
||||
void KeyboardDeviceDownHandler(object sender, KeyboardKeyEventArgs e)
|
||||
|
@ -183,14 +187,14 @@ 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;
|
||||
}
|
||||
|
||||
void KeyboardDeviceUpHandler(object sender, KeyboardKeyEventArgs e)
|
||||
{
|
||||
legacy_keyboard_keys.Remove(e.Key);
|
||||
legacy_keyboard_keys.Remove(e.Key);
|
||||
legacy_keyboard_modifiers = e.Modifiers;
|
||||
legacy_keyboard_state = e.Keyboard;
|
||||
}
|
||||
|
|
|
@ -210,7 +210,15 @@ namespace OpenTK.Input
|
|||
internal void HandleKeyDown(object sender, KeyboardKeyEventArgs e)
|
||||
{
|
||||
state = e.Keyboard;
|
||||
KeyDown(this, e);
|
||||
// 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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue