Skip to content

Commit

Permalink
Fix input spam while performing an unblocked action (i.e. walking)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakota628 committed Jul 11, 2015
1 parent be58b2e commit d9dffbf
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion gtav_console/Console/DeveloperConsole.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.EnterpriseServices.Internal;
Expand Down Expand Up @@ -44,6 +45,8 @@ public class DeveloperConsole : Script {
private int _lastBlinkTime;
private int _lineOffset;

private List<Keys> keyWasDown = new List<Keys>();

/// <summary>
/// Whether or not console debug is enabled
/// </summary>
Expand All @@ -64,6 +67,7 @@ public DeveloperConsole() {

Tick += OnTick;
KeyDown += OnKeyDown;
KeyUp += OnKeyUp;

CommandDispatcher = new CommandDispatcher();
ObjectSelector = new ObjectSelector();
Expand Down Expand Up @@ -120,6 +124,15 @@ internal static void RegisterConsoleScript(Script s, OnConsoleAttached c) {

#region Handle Console

/// <summary>
/// Handles key releases
/// </summary>
/// <param name="sender">The object sending the event</param>
/// <param name="e">The event arguments</param>
private void OnKeyUp(object sender, KeyEventArgs e) {
if (keyWasDown.Contains(e.KeyCode)) keyWasDown.Remove(e.KeyCode);
}

/// <summary>
/// Handles key presses
/// </summary>
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}

/// <summary>
/// This method is called every game tick
/// </summary>
Expand Down

0 comments on commit d9dffbf

Please sign in to comment.