Example #1
0
 /// <summary>
 /// Handles the key pressed event.
 /// </summary>
 /// <param name="e"></param>
 public void KeyPressed(KeyPressEventArgs e)
 {
     if ((e.KeyChar >= ' ') && (e.KeyChar <= '~'))
     {
         KeyPressQueue.Enqueue(0x80000 | (int)e.KeyChar);
     }
 }
Example #2
0
        /// <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);
            }
        }
Example #3
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);
        }
Example #4
0
        /// <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);
        }