Before I go about implementing an I/O queuing system, is there a solution already floating around somewhere? (In Unity or elsewhere.)
I’m pulling keys with Input.GetKeyDown, which trigger timed events. I’d like to keep queuing up input even while these events are running. If a solution already exists, I’d rather use it than reinvent the queue. 
Hiya,
Not sure on the level of complexity you are looking for here but you could do something fairly simple like using an array where you trap and store the keys on an update or a set increment of time that is update through the update. Then in this list, the keys would stack up and you could simply pull from the front of the array.
Would that work for you?
– Clint
Here is an easy example of how to make a simple key queue system. Put this script on a gameObject. To use it do something like:
if (InputManager.get.HasKeys())
string key = InputManager.get.GetNextKey();
using UnityEngine;
using System.Collections;
public class InputManager : MonoBehaviour {
private static InputManager instance;
public static InputManager get {
get {
if (!instance)
Debug.LogError("No InputManager in scene");
return instance;
}
}
private string[] keys = new string[] {"backspace", "tab", "return", "escape", "space", "delete", "enter", "insert", "home", "end", "page up", "page down", "right shift", "left shift", "right ctrl", "left ctrl", "right alt", "left alt", "right cmd", "left cmd"};
private Queue keyQueue;
void Awake() {
instance = this;
keyQueue = new Queue();
}
void Update() {
foreach (string key in keys) {
if (Input.GetKeyDown(key)) {
keyQueue.Enqueue(key);
}
}
}
public string GetNextKey() {
if (keyQueue.Count > 0)
return keyQueue.Dequeue() as string;
else
return "";
}
public bool HasKeys() {
return keyQueue.Count > 0;
}
}
1 Like
Thanks!
(And this certainly warrants a new wish… :roll: )