Skip to content

Commit

Permalink
Fix: Incorrect keyup events in some cases.
Browse files Browse the repository at this point in the history
We must check that our key is actually pressed before sending the keyup event, as otherwise keys depressed using modifers break.
  • Loading branch information
leezer3 committed Mar 18, 2017
1 parent 301fe0e commit f64e353
Showing 1 changed file with 76 additions and 76 deletions.
152 changes: 76 additions & 76 deletions source/OpenBVE/System/Input/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,85 @@

namespace OpenBve
{
internal static partial class MainLoop
{
/// <summary>Called when a KeyDown event is generated</summary>
internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e)
{
if (Loading.Complete == true && e.Key == OpenTK.Input.Key.F4 && e.Alt == true)
{
// Catch standard ALT + F4 quit and push confirmation prompt
Game.Menu.PushMenu(Menu.MenuType.Quit);
return;
}
BlockKeyRepeat = true;
//Check for modifiers
if (e.Shift) CurrentKeyboardModifier |= Interface.KeyboardModifier.Shift;
if (e.Control) CurrentKeyboardModifier |= Interface.KeyboardModifier.Ctrl;
if (e.Alt) CurrentKeyboardModifier |= Interface.KeyboardModifier.Alt;
internal static partial class MainLoop
{
/// <summary>Called when a KeyDown event is generated</summary>
internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e)
{
if (Loading.Complete == true && e.Key == OpenTK.Input.Key.F4 && e.Alt == true)
{
// Catch standard ALT + F4 quit and push confirmation prompt
Game.Menu.PushMenu(Menu.MenuType.Quit);
return;
}
BlockKeyRepeat = true;
//Check for modifiers
if (e.Shift) CurrentKeyboardModifier |= Interface.KeyboardModifier.Shift;
if (e.Control) CurrentKeyboardModifier |= Interface.KeyboardModifier.Ctrl;
if (e.Alt) CurrentKeyboardModifier |= Interface.KeyboardModifier.Alt;
if (Game.CurrentInterface == Game.InterfaceType.Menu && Game.Menu.IsCustomizingControl())
{
{
Game.Menu.SetControlKbdCustomData(e.Key, CurrentKeyboardModifier);
return;
}
//Traverse the controls array
for (int i = 0; i < Interface.CurrentControls.Length; i++)
{
//If we're using keyboard for this input
if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Keyboard)
{
//Compare the current and previous keyboard states
//Only process if they are different
if (!Enum.IsDefined(typeof(Key), Interface.CurrentControls[i].Key)) continue;
if (e.Key == Interface.CurrentControls[i].Key & Interface.CurrentControls[i].Modifier == CurrentKeyboardModifier)
{
return;
}
//Traverse the controls array
for (int i = 0; i < Interface.CurrentControls.Length; i++)
{
//If we're using keyboard for this input
if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Keyboard)
{
//Compare the current and previous keyboard states
//Only process if they are different
if (!Enum.IsDefined(typeof(Key), Interface.CurrentControls[i].Key)) continue;
if (e.Key == Interface.CurrentControls[i].Key & Interface.CurrentControls[i].Modifier == CurrentKeyboardModifier)
{

Interface.CurrentControls[i].AnalogState = 1.0;
Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Pressed;
//Key repeats should not be added in non-game interface modes, unless they are Menu Up/ Menu Down commands
if (Game.CurrentInterface == Game.InterfaceType.Normal || Interface.CurrentControls[i].Command == Interface.Command.MenuUp || Interface.CurrentControls[i].Command == Interface.Command.MenuDown)
{
if (Interface.CurrentControls[i].Command == Interface.Command.CameraInterior |
Interface.CurrentControls[i].Command == Interface.Command.CameraExterior |
Interface.CurrentControls[i].Command == Interface.Command.CameraFlyBy |
Interface.CurrentControls[i].Command == Interface.Command.CameraTrack)
{
Interface.CurrentControls[i].AnalogState = 1.0;
Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Pressed;
//Key repeats should not be added in non-game interface modes, unless they are Menu Up/ Menu Down commands
if (Game.CurrentInterface == Game.InterfaceType.Normal || Interface.CurrentControls[i].Command == Interface.Command.MenuUp || Interface.CurrentControls[i].Command == Interface.Command.MenuDown)
{
if (Interface.CurrentControls[i].Command == Interface.Command.CameraInterior |
Interface.CurrentControls[i].Command == Interface.Command.CameraExterior |
Interface.CurrentControls[i].Command == Interface.Command.CameraFlyBy |
Interface.CurrentControls[i].Command == Interface.Command.CameraTrack)
{
//HACK: We don't want to bounce between camera modes when holding down the mode switch key
continue;
}
AddControlRepeat(i);
}
}
}
}
BlockKeyRepeat = false;
//Remember to reset the keyboard modifier after we're done, else it repeats.....
CurrentKeyboardModifier = Interface.KeyboardModifier.None;
}
continue;
}
AddControlRepeat(i);
}
}
}
}
BlockKeyRepeat = false;
//Remember to reset the keyboard modifier after we're done, else it repeats.....
CurrentKeyboardModifier = Interface.KeyboardModifier.None;
}

/// <summary>Called when a KeyUp event is generated</summary>
internal static void keyUpEvent(object sender, KeyboardKeyEventArgs e)
{
//We don't need to check for modifiers on key up
BlockKeyRepeat = true;
//Traverse the controls array
for (int i = 0; i < Interface.CurrentControls.Length; i++)
{
//If we're using keyboard for this input
if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Keyboard)
{
//Compare the current and previous keyboard states
//Only process if they are different
if (!Enum.IsDefined(typeof(Key), Interface.CurrentControls[i].Key)) continue;
if (e.Key == Interface.CurrentControls[i].Key)
{
Interface.CurrentControls[i].AnalogState = 0.0;
Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Released;
RemoveControlRepeat(i);
}
}
}
BlockKeyRepeat = false;
}
}
/// <summary>Called when a KeyUp event is generated</summary>
internal static void keyUpEvent(object sender, KeyboardKeyEventArgs e)
{
//We don't need to check for modifiers on key up
BlockKeyRepeat = true;
//Traverse the controls array
for (int i = 0; i < Interface.CurrentControls.Length; i++)
{
//If we're using keyboard for this input
if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Keyboard)
{
//Compare the current and previous keyboard states
//Only process if they are different
if (!Enum.IsDefined(typeof(Key), Interface.CurrentControls[i].Key)) continue;
if (e.Key == Interface.CurrentControls[i].Key & Interface.CurrentControls[i].AnalogState == 1.0 & Interface.CurrentControls[i].DigitalState > Interface.DigitalControlState.Released)
{
Interface.CurrentControls[i].AnalogState = 0.0;
Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Released;
RemoveControlRepeat(i);
}
}
}
BlockKeyRepeat = false;
}
}
}

0 comments on commit f64e353

Please sign in to comment.