/// <summary> /// Gets a key from the key queue. Return 0 if none available. /// </summary> /// <returns></returns> public int GetKey() { int c; if (KeyPressQueue.TryDequeue(out c)) { return(c); } else { return(0); } }
/// <summary> /// Wait for and return either ACCEPT or ABORT. /// </summary> /// <returns></returns> public int WaitAcceptAbort() { int action; int ignore; // Ignore anything currently on the key press queue. while (KeyPressQueue.TryDequeue(out ignore)) { ; } // Now wait for the the next key. while ((action = CheckAcceptAbort()) == -1) { Thread.Sleep(1); } return(action); }
/// <summary> /// Waits for the next key to be pressed then returns the value. /// </summary> /// <param name="clearQueue">Whether to clear what is on the queue before waiting.</param> /// <returns>The key that was pressed.</returns> public int WaitForKey(bool clearQueue = true) { int ignore; int key; if (clearQueue) { // Ignore anything currently on the key press queue. while (KeyPressQueue.TryDequeue(out ignore)) { ; } } // Now wait for the the next key. while ((key = GetKey()) == 0) { Thread.Sleep(1); } return(key); }