diff --git a/gtav_console/Console/DeveloperConsole.cs b/gtav_console/Console/DeveloperConsole.cs index a702215..c04ddf7 100644 --- a/gtav_console/Console/DeveloperConsole.cs +++ b/gtav_console/Console/DeveloperConsole.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; using System.EnterpriseServices.Internal; @@ -44,6 +45,8 @@ public class DeveloperConsole : Script { private int _lastBlinkTime; private int _lineOffset; + private List keyWasDown = new List(); + /// /// Whether or not console debug is enabled /// @@ -64,6 +67,7 @@ public DeveloperConsole() { Tick += OnTick; KeyDown += OnKeyDown; + KeyUp += OnKeyUp; CommandDispatcher = new CommandDispatcher(); ObjectSelector = new ObjectSelector(); @@ -120,6 +124,15 @@ internal static void RegisterConsoleScript(Script s, OnConsoleAttached c) { #region Handle Console + /// + /// Handles key releases + /// + /// The object sending the event + /// The event arguments + private void OnKeyUp(object sender, KeyEventArgs e) { + if (keyWasDown.Contains(e.KeyCode)) keyWasDown.Remove(e.KeyCode); + } + /// /// Handles key presses /// @@ -131,10 +144,13 @@ private void OnKeyDown(object sender, KeyEventArgs e) { if (Array.IndexOf(ConsoleSettings.HideKeys, e.KeyCode) >= 0) { ShowConsole(_isHidden); e.SuppressKeyPress = true; + return; } - else if (e.KeyCode == Keys.Escape) { + + if (e.KeyCode == Keys.Escape) { ShowConsole(false); e.SuppressKeyPress = true; + return; } if (_isHidden) { @@ -198,6 +214,7 @@ private void OnKeyDown(object sender, KeyEventArgs e) { var s = NativeMethods.GetCharsFromKeys(e.KeyData, (e.Modifiers & Keys.Shift) == Keys.Shift, (e.Modifiers & Keys.Alt) == Keys.Alt); if (s != null) { + if (SetKeyDown(e.KeyCode)) return; var c = s[0]; if ((NativeMethods.GetKeyState(VkCapital) & 0x8000) == 0x8000 || (NativeMethods.GetKeyState(VkCapital) & 1) == 1 && char.IsLetter(c)) @@ -211,6 +228,12 @@ private void OnKeyDown(object sender, KeyEventArgs e) { e.SuppressKeyPress = true; } + private bool SetKeyDown(Keys k) { + bool ret = keyWasDown.Contains(k); + if (!keyWasDown.Contains(k)) keyWasDown.Add(k); + return ret; + } + /// /// This method is called every game tick ///