Exemple #1
0
 public void OnKeyReleased(KeyEvent e)
 {
 }
Exemple #2
0
 public void OnKeyTyped(KeyEvent e)
 {
 }
Exemple #3
0
 public void OnKeyPressed(KeyEvent e)
 {
     StateManager sm = StateManager.GetInstance();
     if (sm.GetRunningGame() != StateManager.RunningGame.None && e.key == Keys.Escape)
     {
         if (sm.GetState() != StateManager.State.Paused)
         {
             MenuManager.GetInstance().ShowMenu(MenuManager.Menu.IngameMenu);
             StateManager.GetInstance().SetState(StateManager.State.Paused);
         }
         else
         {
             MenuManager.GetInstance().ShowMenu(MenuManager.Menu.NoMenu);
             StateManager.GetInstance().SetState(StateManager.State.Running);
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// User pressed a key in the message textfield.
        /// </summary>
        /// <param name="e">The event</param>
        public void OnKeyPressed(KeyEvent e)
        {
            if (e.key.ToString() == "Enter")
            {
                ChatServerConnectionManager chat = ChatServerConnectionManager.GetInstance();
                String message = chat.user.username + ": " + messageTextField.text;
                messageTextField.text = "";
                // AddMessageToLog(message);
                Packet packet = new Packet();

                packet.SetHeader(Headers.CHAT_MESSAGE);
                packet.AddInt(chat.user.channelID);
                packet.AddString(message);
                chat.SendPacket(packet);
            }
        }
Exemple #5
0
        private void ProcessKey(KeyEvent e)
        {
            if (this.maxLength != 0 && this.text.Length >= this.maxLength) return;
            if (this.isFocussed)
            {
                if (onTextFieldKeyPressedListeners != null) onTextFieldKeyPressedListeners(e);
                String keyString = e.key.ToString();
                if (keyString.Equals("Left"))
                {
                    if (this.caret.index > 0)
                    {
                        // Console.Out.WriteLine(this.caret.index);
                        this.caret.index--;
                    }
                    else if (this.caret.row > 0)
                    {
                        this.caret.row--;
                        this.caret.index = this.caret.GetTextOnCaretRow().Length - 1;
                    }
                }
                else if (keyString.Equals("Right"))
                {
                    if (this.caret.index < (this.caret.GetTextOnCaretRow().Length)) this.caret.index++;
                    else
                    {
                        int rowCount = this.text.Split(new char[] { '\n' }).Length;
                        if (this.caret.row < rowCount - 1)
                        {
                            this.caret.index = 0;
                            this.caret.row++;
                        }
                    }
                }
                else if (keyString.Equals("Up"))
                {
                    if (this.caret.row > 0) this.caret.row--;
                }
                else if (keyString.Equals("Down"))
                {
                    if (this.rows > 1 && this.caret.row < this.text.Split(new char[] { '\n' }).Length) this.caret.row++;
                }
                else if (keyString.Contains("Back"))
                {
                    if (this.caret.index > 0) DeleteCharacterAt(this.caret.GetCaretArrayIndex(), true);
                    else if (this.caret.row > 0)
                    {
                        this.caret.row--;
                        this.caret.index = this.caret.GetTextOnCaretRow().Length;
                    }
                }
                else if (keyString.Contains("Delete"))
                {
                    if (this.caret.index < this.text.Length) DeleteCharacterAt(this.caret.GetCaretArrayIndex(), false);
                }
                else if (keyString.Equals("Enter"))
                {
                    if (this.caret.row < this.rows - 1)
                    {
                        this.InsertStringAtCaret("\n ");
                        this.caret.row++;
                        this.caret.index = 1;
                    }
                    // this.OnFocusLost();
                }
                else if (keyString.Equals("Home"))
                {
                    this.caret.index = 0;
                }
                else if (keyString.Equals("End"))
                {
                    this.caret.index = this.text.Length;
                }
                else if (keyString.Equals("PageUp"))
                {
                    this.caret.row = 0;
                    return;
                }
                else if (keyString.Equals("PageDown"))
                {
                    this.caret.row = this.rows - 1;
                    return;
                }
                else if (keyString.Equals("Tab") || keyString.Equals("ScrollLock") || keyString.Equals("Insert"))
                {
                    // Do nothing
                    return;
                }
                else if (keyString.Equals("F1") ||
                    keyString.Equals("F2") ||
                    keyString.Equals("F3") ||
                    keyString.Equals("F4") ||
                    keyString.Equals("F5") ||
                    keyString.Equals("F6") ||
                    keyString.Equals("F7") ||
                    keyString.Equals("F8") ||
                    keyString.Equals("F9") ||
                    keyString.Equals("F10") ||
                    keyString.Equals("F11") ||
                    keyString.Equals("F12"))
                {
                    // Do nothing
                    return;
                }
                else
                {
                    String typedChar = "";
                    #region Convert keyString to a typedChar
                    if (keyString.Equals("Space")) typedChar = " ";
                    else if (keyString.Equals("OemQuestion"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "?";
                        else typedChar = "/";
                    }
                    else if (keyString.Equals("OemPeriod"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = ">";
                        else typedChar = ".";
                    }
                    else if (keyString.Equals("OemSemicolon"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = ":";
                        else typedChar = ";";
                    }
                    else if (keyString.Equals("OemQuotes"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "\"";
                        else typedChar = "'";
                    }
                    else if (keyString.Equals("OemComma"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "<";
                        else typedChar = ",";
                    }
                    else if (keyString.Equals("OemOpenBrackets"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "{";
                        else typedChar = "[";
                    }
                    else if (keyString.Equals("OemCloseBrackets"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "}";
                        else typedChar = "]";
                    }
                    else if (keyString.Equals("OemPipe"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "|";
                        else typedChar = "\\";
                    }
                    else if (keyString.Equals("OemMinus"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "_";
                        else typedChar = "-";
                    }
                    else if (keyString.Equals("OemPlus"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "+";
                        else typedChar = "=";
                    }
                    else if (keyString.Equals("OemTilde"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "~";
                        else typedChar = "`";
                    }
                    else if (keyString.Equals("D0"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = ")";
                        else typedChar = "0";
                    }
                    else if (keyString.Equals("D1"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "!";
                        else typedChar = "1";
                    }
                    else if (keyString.Equals("D2"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "@";
                        else typedChar = "2";
                    }
                    else if (keyString.Equals("D3"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "#";
                        else typedChar = "3";
                    }
                    else if (keyString.Equals("D4"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "$";
                        else typedChar = "4";
                    }
                    else if (keyString.Equals("D5"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "%";
                        else typedChar = "5";
                    }
                    else if (keyString.Equals("D6"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "^";
                        else typedChar = "6";
                    }
                    else if (keyString.Equals("D7"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "&";
                        else typedChar = "7";
                    }
                    else if (keyString.Equals("D8"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "*";
                        else typedChar = "8";
                    }
                    else if (keyString.Equals("D9"))
                    {
                        if (e.modifiers.Contains(KeyEvent.Modifier.SHIFT)) typedChar = "(";
                        else typedChar = "9";
                    }
                    // Remaining num pads and whatnot
                    else if (keyString.Contains("0")) typedChar = "0";
                    else if (keyString.Contains("1")) typedChar = "1";
                    else if (keyString.Contains("2")) typedChar = "2";
                    else if (keyString.Contains("3")) typedChar = "3";
                    else if (keyString.Contains("4")) typedChar = "4";
                    else if (keyString.Contains("5")) typedChar = "5";
                    else if (keyString.Contains("6")) typedChar = "6";
                    else if (keyString.Contains("7")) typedChar = "7";
                    else if (keyString.Contains("8")) typedChar = "8";
                    else if (keyString.Contains("9")) typedChar = "9";
                    else
                    {
                        if (keyString.Length == 1)
                        {
                            if (!e.modifiers.Contains(KeyEvent.Modifier.SHIFT))
                                keyString = keyString.ToLower();
                        }
                        typedChar = keyString;
                    }
                    #endregion

                    this.InsertStringAtCaret(typedChar);
                }
            }
        }
Exemple #6
0
 public void OnKeyTyped(KeyEvent e)
 {
     ProcessKey(e);
     // Console.Out.WriteLine("Typed: " + e.key.ToString());
 }
Exemple #7
0
 public void OnKeyReleased(KeyEvent e)
 {
     // Console.Out.WriteLine("Released: " + e.key.ToString());
     // throw new NotImplementedException();
 }