Exemplo n.º 1
0
        /// <summary>
        /// перехват нажимания кнопок
        /// </summary>
        /// <param name="key">Нажатая кнопка</param>
        void MainFormKeyPressedEvent(Keys key)
        {
            var mod = Enum.GetValues(typeof(Keys)).Cast<Keys>().Where(x => ModifierKeys.ToString().Split(',').Select(y => y.Trim()).Contains(x.ToString())).ToArray();
            curentMod1Key = mod.Length > 0 ? mod[0] : Keys.None;
            curentMod2Key = mod.Length > 1 ? mod[1] : Keys.None;

            if (key != Keys.ControlKey && key != Keys.ShiftKey)
            {
                ObjHotKey.mainKey = key;
                ObjHotKey.mod1 = curentMod1Key;
                ObjHotKey.mod2 = curentMod2Key;

                var sb = new StringBuilder(key.ToString());
                if (curentMod1Key != Keys.None && curentMod1Key != null)
                {
                    sb.Append(string.Format(" + {0}", curentMod1Key));
                    ObjHotKey.mod1 = curentMod1Key;
                }
                if (curentMod2Key != Keys.None && curentMod2Key != null)
                {
                    sb.Append(string.Format(" + {0}", curentMod2Key));
                    ObjHotKey.mod2 = curentMod2Key;
                }

                txtbxHotKeyNewValue.Text = sb.ToString();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Конструктор копирования
 /// </summary>
 public ApplicationMessageBinding(ApplicationMessageBinding k)
     : this(k.Message, k.mainKey, k.messageType)
 {
     stopFurtherProcessing = k.stopFurtherProcessing;
     mod1 = k.mod1;
     mod2 = k.mod2;
     ActionDescription = k.ActionDescription;
 }
Exemplo n.º 3
0
        private void AssertAKeyPress(Keys key)
        {
            int neededInputs = 2;
            var modifiers = new Keys?[3];
            if (key.HasFlag(Keys.Shift))
            {
                modifiers[0] = Keys.ShiftKey;
                neededInputs += 2;
            }
            if (key.HasFlag(Keys.Control))
            {
                modifiers[1] = Keys.ControlKey;
                neededInputs += 2;
            }
            if (key.HasFlag(Keys.Alt))
            {
                modifiers[2] = Keys.Menu;
                neededInputs += 2;
            }

            Assert.AreEqual(neededInputs, _inputs.Count);

            int currentInput = 0;
            foreach (var modifier in modifiers)
            {
                if (modifier.HasValue)
                {
                    AssertIsKeyDownInputFor(modifier.Value, _inputs[currentInput++]);
                }
            }

            AssertIsKeyDownInputFor(key, _inputs[currentInput++]);
            AssertIsKeyUpInputFor(key, _inputs[currentInput++]);

            foreach (var modifier in modifiers)
            {
                if (modifier.HasValue)
                {
                    AssertIsKeyUpInputFor(modifier.Value, _inputs[currentInput++]);
                }
            }
        }
Exemplo n.º 4
0
 protected override void OnKeyDown(KeyEventArgs e)
 {
     m_Key = e.KeyCode;
     switch (e.KeyCode)
     {
         case Keys.ControlKey:
         case Keys.Menu:
         case Keys.ShiftKey:
             m_Key = null;
             break;
         case Keys.Back:
             if (!e.Control && !e.Alt && !e.Shift)
             {
                 Text = string.Empty;
                 return;
             }
             break;
     }
     var hk = new Hotkey { Control = e.Control, Alt = e.Alt, Shift = e.Shift, Key = m_Key };
     Text = hk.ToString();
 }
Exemplo n.º 5
0
 public void Reset()
 {
     _value = Default;
 }
Exemplo n.º 6
0
 public Key(Keys defaultKey, Keys? value = null)
 {
     Default = defaultKey;
     _value = value;
 }
Exemplo n.º 7
0
		void handleKey( Keys key )
		{
			if( key != Keys.Tab && key != Keys.LeftShift && key != Keys.RightShift && key != Keys.RightAlt && key != Keys.LeftAlt && key != Keys.RightControl && key != Keys.LeftControl )
				_tabIndex = -1;

			if( key != Keys.OemTilde && key != Keys.Oem8 && key != Keys.Enter && _repeatKey != key )
			{
				_repeatKey = key;
				_repeatCounter = 0;
			}

			switch( key )
			{
				default:
					if( key.ToString().Length == 1 )
					{
						if( InputUtils.isShiftDown() )
							_currentText += key.ToString();
						else
							_currentText += key.ToString().ToLower();
					}
				break;

				case( Keys.D1 ):
					if( InputUtils.isShiftDown() )
						_currentText += '!';
					else
						_currentText += '1';
				break;
				case( Keys.D2 ):
					if( InputUtils.isShiftDown() )
						_currentText += '@';
					else
						_currentText += '2';
				break;
				case( Keys.D3 ):
					if( InputUtils.isShiftDown() )
						_currentText += '#';
					else
						_currentText += '3';
				break;
				case( Keys.D4 ):
					if( InputUtils.isShiftDown() )
						_currentText += '$';
					else
						_currentText += '4';
				break;
				case( Keys.D5 ):
					if( InputUtils.isShiftDown() )
						_currentText += '%';
					else
						_currentText += '5';
				break;
				case( Keys.D6 ):
					if( InputUtils.isShiftDown() )
						_currentText += '^';
					else
						_currentText += '6';
				break;
				case( Keys.D7 ):
					if( InputUtils.isShiftDown() )
						_currentText += '&';
					else
						_currentText += '7';
				break;
				case( Keys.D8 ):
					if( InputUtils.isShiftDown() )
						_currentText += '*';
					else
						_currentText += '8';
				break;
				case( Keys.D9 ):
					if( InputUtils.isShiftDown() )
						_currentText += '(';
					else
						_currentText += '9';
				break;
				case( Keys.D0 ):
					if( InputUtils.isShiftDown() )
						_currentText += ')';
					else
						_currentText += '0';
				break;
				case( Keys.OemComma):
					if( InputUtils.isShiftDown() )
						_currentText += '<';
					else
						_currentText += ',';
				break;
				case Keys.OemPeriod:
					if( InputUtils.isShiftDown() )
						_currentText += '>';
					else
						_currentText += '.';
				break;
				case Keys.OemQuestion:
					if( InputUtils.isShiftDown() )
						_currentText += '?';
					else
						_currentText += '/';
				break;
				case Keys.OemSemicolon:
					if( InputUtils.isShiftDown() )
						_currentText += ':';
					else
						_currentText += ';';
				break;
				case Keys.OemQuotes:
					if( InputUtils.isShiftDown() )
						_currentText += '"';
					else
						_currentText += '\'';
				break;
				case Keys.OemBackslash:
					if( InputUtils.isShiftDown() )
						_currentText += '|';
					else
						_currentText += '\\';
				break;
				case Keys.OemOpenBrackets:
					if( InputUtils.isShiftDown() )
						_currentText += '{';
					else
						_currentText += '[';
				break;
				case Keys.OemCloseBrackets:
					if( InputUtils.isShiftDown() )
						_currentText += '}';
					else
						_currentText += ']';
				break;
				case Keys.OemMinus:
					if( InputUtils.isShiftDown() )
						_currentText += '_';
					else
						_currentText += '-';
				break;
				case Keys.OemPlus:
					if( InputUtils.isShiftDown() )
						_currentText += '+';
					else
						_currentText += '=';
				break;

				case Keys.Space:
					_currentText += " ";
				break;
				case Keys.Back:
					if( _currentText.Length > 0 )
						_currentText = _currentText.Substring( 0, _currentText.Length - 1 );
				break;
				case Keys.Delete:
					_currentText = "";
				break;

				case Keys.Up:
					if( _seekIndex < _commandHistory.Count - 1 )
					{
						_seekIndex++;
						_currentText = string.Join( " ", _commandHistory[_seekIndex] );
					}
				break;
				case Keys.Down:
					if( _seekIndex > -1 )
					{
						_seekIndex--;
						if( _seekIndex == -1 )
							_currentText = "";
						else
							_currentText = string.Join( " ", _commandHistory[_seekIndex] );
					}
				break;

				case Keys.Tab:
					if( InputUtils.isShiftDown() )
					{
						if( _tabIndex == -1 )
						{
							_tabSearch = _currentText;
							findLastTab();
						}
						else
						{
							_tabIndex--;
							if( _tabIndex < 0 || ( _tabSearch != "" && _sorted[_tabIndex].IndexOf( _tabSearch ) != 0 ) )
								findLastTab();
						}
					}
					else
					{
						if( _tabIndex == -1 )
						{
							_tabSearch = _currentText;
							findFirstTab();
						}
						else
						{
							_tabIndex++;
							if( _tabIndex >= _sorted.Count || ( _tabSearch != "" && _sorted[_tabIndex].IndexOf( _tabSearch ) != 0 ) )
								findFirstTab();
						}
					}
					if( _tabIndex != -1 )
						_currentText = _sorted[_tabIndex];
				break;

				case Keys.F1:
				case Keys.F2:
				case Keys.F3:
				case Keys.F4:
				case Keys.F5:
				case Keys.F6:
				case Keys.F7:
				case Keys.F8:
				case Keys.F9:
				case Keys.F10:
				case Keys.F11:
				case Keys.F12:
					executeFunctionKeyAction( (int)( key - Keys.F1 ) );
				break;

				case Keys.Enter:
					if( _currentText.Length > 0 )
						enterCommand();
				break;

				case Keys.Oem8:
				case Keys.OemTilde:
					isOpen = _canOpen = false;
				break;
			}
		}
Exemplo n.º 8
0
		void updateOpen()
		{
			_oldState = _currentState;
			_currentState = Keyboard.GetState();

			_underscoreCounter += Time.deltaTime;
			while( _underscoreCounter >= UNDERSCORE_TIME )
			{
				_underscoreCounter -= UNDERSCORE_TIME;
				_underscore = !_underscore;
			}

			if( _repeatKey.HasValue )
			{
				if( _currentState[_repeatKey.Value] == KeyState.Down )
				{
					_repeatCounter += Time.deltaTime;

					while( _repeatCounter >= REPEAT_DELAY )
					{
						handleKey( _repeatKey.Value );
						_repeatCounter -= REPEAT_EVERY;
					}
				}
				else
					_repeatKey = null;
			}

			foreach( var key in _currentState.GetPressedKeys() )
			{
				if( _oldState[key] == KeyState.Up )
				{
					handleKey( key );
					break;
				}
			}
		}
Exemplo n.º 9
0
        private bool HandleStudioKey(Keys keyData)
        {
            Keys? nullable = _firstLetter;
            _firstLetter = null;
            Keys valueOrDefault = nullable.GetValueOrDefault();
            if (!nullable.HasValue)
            {
                switch (keyData)
                {
                    case (Keys.Control | Keys.E):
                    case (Keys.Control | Keys.K):
                    case (Keys.Control | Keys.M):
                    case (Keys.Control | Keys.W):
                        _firstLetter = new Keys?(keyData);
                        return true;

                    case (Keys.Control | Keys.G):
                        this.ExecuteQuery();
                        return true;

                    case (Keys.Control | Keys.J):
                        this.ListMembers();
                        return true;
                }
                return false;
            }
            switch (valueOrDefault)
            {
                case (Keys.Control | Keys.K):
                    valueOrDefault = keyData;
                    if (valueOrDefault > Keys.X)
                    {
                        if (valueOrDefault > (Keys.Control | Keys.L))
                        {
                            switch (valueOrDefault)
                            {
                                case (Keys.Control | Keys.S):
                                    goto Label_013B;

                                case (Keys.Control | Keys.T):
                                    goto Label_0149;

                                case (Keys.Control | Keys.U):
                                    goto Label_0150;
                            }
                            if (valueOrDefault != (Keys.Control | Keys.X))
                            {
                                goto Label_0149;
                            }
                            goto Label_012D;
                        }
                        if (valueOrDefault == (Keys.Control | Keys.C))
                        {
                            goto Label_00FE;
                        }
                        if (valueOrDefault == (Keys.Control | Keys.L))
                        {
                            break;
                        }
                    }
                    else if (valueOrDefault > Keys.L)
                    {
                        switch (valueOrDefault)
                        {
                            case Keys.S:
                                goto Label_013B;

                            case Keys.U:
                                goto Label_0150;

                            case Keys.X:
                                goto Label_012D;
                        }
                    }
                    else
                    {
                        switch (valueOrDefault)
                        {
                            case Keys.C:
                                goto Label_00FE;
                        }
                    }
                    goto Label_0149;

                case (Keys.Control | Keys.M):
                    switch (keyData)
                    {
                        case Keys.L:
                        case Keys.O:
                        case (Keys.Control | Keys.L):
                        case (Keys.Control | Keys.O):
                            this.ToggleAllOutlining();
                            return true;

                        case Keys.M:
                        case (Keys.Control | Keys.M):
                            this.ToggleOutlining(false);
                            return true;
                    }
                    return false;

                case (Keys.Control | Keys.W):
                    switch (keyData)
                    {
                        case Keys.L:
                        case (Keys.Control | Keys.L):
                            MainForm.Instance.FocusSchemaExplorer();
                            return true;

                        case Keys.S:
                        case (Keys.Control | Keys.S):
                            MainForm.Instance.FocusQueries();
                            return true;
                    }
                    return false;

                case (Keys.Control | Keys.E):
                    switch (keyData)
                    {
                        case Keys.C:
                        case (Keys.Control | Keys.C):
                            this.CommentSelection();
                            return true;

                        case Keys.U:
                        case (Keys.Control | Keys.U):
                            this.UncommentSelection();
                            return true;
                    }
                    return false;

                default:
                    return false;
            }
            this.ListMembers();
            return true;
        Label_00FE:
            this.CommentSelection();
            return true;
        Label_012D:
            this.InsertSnippet(false);
            return true;
        Label_013B:
            this.InsertSnippet(true);
            return true;
        Label_0149:
            return false;
        Label_0150:
            this.UncommentSelection();
            return true;
        }
Exemplo n.º 10
0
        internal void UpdateOpen()
        {
            oldState = currentState;
            currentState = Keyboard.GetState();

            underscoreCounter++;
            if (underscoreCounter == UNDERSCORE_TIME)
            {
                underscoreCounter = 0;
                underscore = !underscore;
            }

            if (repeatKey.HasValue)
            {
                if (currentState[repeatKey.Value] == KeyState.Down)
                {
                    if (repeatCounter < REPEAT_DELAY)
                        repeatCounter++;
                    else
                    {
                        if (repeatCounter == REPEAT_DELAY)
                        {
                            repeatCounter++;
                            HandleKey(repeatKey.Value);
                        }
                        else
                        {
                            repeatCounter++;
                            if (repeatCounter == REPEAT_DELAY + REPEAT_EVERY)
                                repeatCounter = REPEAT_DELAY;
                        }
                    }
                }
                else
                    repeatKey = null;
            }

            foreach (Keys key in currentState.GetPressedKeys())
            {
                if (oldState[key] == KeyState.Up)
                {
                    HandleKey(key);
                    break;
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Метод восстановления объекта горячей клавиши из строки. Этот метод обратный методу "ToString()"
        /// </summary>
        public static ApplicationMessageBinding Parse(string str)
        {
            var messageSrt = string.Empty;
            var keySrt = string.Empty;
            var mod1Srt = string.Empty;
            var mod2Srt = string.Empty;
            var messageTypeSrt = string.Empty;
            var stopFurtherProcessingSrt = string.Empty;

            foreach (var s in str.Split(','))
            {
                var param = s.Split(':');
                if (param.Length < 2 || string.IsNullOrEmpty(param[0].Trim()) || string.IsNullOrEmpty(param[1].Trim()))
                {
                    Logger.Error(String.Format("Неправилиный формат записи пользовательских настроек горячих клавиш в файле UserSettings. Ошибка в  \"{0}\"", s));
                    continue; //Это значить что в паре "ключ / значение" один или оба отсутствуют
                }

                switch (param[0])
                {
                    case "message":
                        messageSrt = param[1];
                        break;
                    case "key":
                        keySrt = param[1];
                        break;
                    case "mod1":
                        mod1Srt = param[1];
                        break;
                    case "mod2":
                        mod2Srt = param[1];
                        break;
                    case "messageType":
                        messageTypeSrt = param[1];
                        break;
                    case "stopFurtherProcessing":
                        stopFurtherProcessingSrt = param[1];
                        break;
                }
            }

            ApplicationMessage message;
            Keys key;
            Keys? mod1;
            Keys? mod2;

            WindowMessage messageType;
            bool stopFurtherProcessing;

            try
            {
                message = Enum.GetValues(typeof (ApplicationMessage)).Cast<ApplicationMessage>().First(x => x.ToString() == messageSrt);
                key = Enum.GetValues(typeof (Keys)).Cast<Keys>().First(x => x.ToString() == keySrt);
                mod1 = Enum.GetValues(typeof (Keys)).Cast<Keys>().FirstOrDefault(x => x.ToString() == mod1Srt);
                mod2 = Enum.GetValues(typeof (Keys)).Cast<Keys>().FirstOrDefault(x => x.ToString() == mod2Srt);

                messageType = Enum.GetValues(typeof (WindowMessage)).Cast<WindowMessage>().First(x => x.ToString() == messageTypeSrt);
                stopFurtherProcessing = stopFurtherProcessingSrt == "True";
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка при попытке распарсить кастомные настройки горячих клавиш из файла UserSettings", ex);
                return null;
            }

            return new ApplicationMessageBinding(message, key, messageType) { mod1 = mod1, mod2 = mod2, stopFurtherProcessing = stopFurtherProcessing };
        }
Exemplo n.º 12
0
        public override void Update( GameTime gameTime )
        {
            base.Update( gameTime );

            double currMillis = gameTime.TotalGameTime.TotalMilliseconds;

            if ( currMillis - mLastCursorBlink >= CursorBlinkFrequency )
            {
                mCursorVisible = !mCursorVisible;
                mLastCursorBlink = currMillis;
            }

            if ( !Input.CheckFocus( this ) )
                return;

            string oldText = Text;
            int oldInputPos = InputPos;

            Func<Keys, bool> notModKey = k => { return k < Keys.LeftShift || k > Keys.RightAlt; };

            var currentKeys = Input.Keyboard.GetPressedKeys().Where( notModKey );
            var prevKeys = Input.OldKeyboard.GetPressedKeys().Where( notModKey );

            var newKeys = currentKeys.Where( ck => !prevKeys.Any( pk => pk == ck ) ).ToList();
            var heldKeys = currentKeys.Intersect( prevKeys );

            if ( mRepeatKey.HasValue && !heldKeys.Contains( mRepeatKey.Value ) )
                mRepeatKey = null;

            var tmpKey = mRepeatKey;

            foreach ( var pair in mKeyHistory.ToArray() )
            {
                if ( !heldKeys.Contains( pair.Key ) )
                {
                    mKeyHistory.Remove( pair.Key );
                    continue;
                }

                if ( pair.Key != mRepeatKey )
                {
                    mRepeatKey = null;
                    if ( currMillis - pair.Value >= this.RepeatDelay )
                        mRepeatKey = pair.Key;
                }
            }

            if ( mRepeatKey != tmpKey )
                mLastRepeat = currMillis;

            foreach ( Keys key in newKeys )
                mKeyHistory[ key ] = currMillis;

            if ( mRepeatKey.HasValue && currMillis - mLastRepeat >= this.RepeatFrequency )
            {
                newKeys.Add( mRepeatKey.Value );
                mLastRepeat = currMillis;
            }

            foreach ( Keys key in newKeys )
            {
                switch ( key )
                {
                case Keys.Home:
                    mIsSelecting = Input.IsShiftDown();
                    InputPos = 0;
                    break;

                case Keys.End:
                    mIsSelecting = Input.IsShiftDown();
                    InputPos = Text.Length;
                    break;

                case Keys.Left:
                    mIsSelecting = Input.IsShiftDown();

                    if ( Input.IsCtrlDown() )
                        InputPos = SkipLeft();

                    else if ( HasSelection && !mIsSelecting )
                        mSelectionAnchor = mInputPos = SelectionStart;

                    else
                        --InputPos;

                    break;

                case Keys.Right:
                    mIsSelecting = Input.IsShiftDown();

                    if ( Input.IsCtrlDown() )
                        InputPos = SkipRight();

                    else if ( HasSelection && !mIsSelecting )
                        mSelectionAnchor = mInputPos = SelectionEnd;

                    else
                        ++InputPos;

                    break;

                case Keys.Back:
                    if ( Text.Length > 0 )
                    {
                        int pos = HasSelection ? InputPos : InputPos - 1;

                        if ( Input.IsCtrlDown() )
                            pos = SkipLeft();

                        if ( pos < 0 )
                            pos = 0;

                        if ( InputPos > SelectionAnchor )
                            pos = SelectionStart;

                        mIsSelecting = true;
                        SelectionAnchor = Math.Max( InputPos, SelectionEnd );
                        InputPos = Math.Min( pos, SelectionStart );

                        InsertText( "" );
                    }
                    break;

                case Keys.Delete:
                    if ( Text.Length > 0 )
                    {
                        int pos = HasSelection ? InputPos : InputPos + 1;

                        if ( Input.IsCtrlDown() )
                            pos = SkipRight();

                        if ( pos > Text.Length )
                            pos = Text.Length;

                        if ( InputPos < SelectionAnchor )
                            pos = SelectionEnd;

                        mIsSelecting = true;
                        SelectionAnchor = Math.Min( InputPos, SelectionStart );
                        InputPos = Math.Max( pos, SelectionEnd );

                        InsertText( "" );
                    }
                    break;

                case Keys.Space:
                    InsertText( " " );
                    break;

                case Keys.Enter:
                    if ( EnableMultiLine )
                        InsertText( "\n" );
                    break;

                default:
                    char glyph = (char) key;

                    if ( char.IsLetter( glyph ) )
                    {
                        if ( Input.IsCtrlDown() )
                        {
                            switch ( glyph )
                            {
                            case 'A':
                                InputPos = Text.Length;
                                SelectionAnchor = 0;
                                break;

                            case 'X':
                                this.Cut();
                                break;

                            case 'C':
                                this.Copy();
                                break;

                            case 'V':
                                this.Paste();
                                break;
                            }
                        }
                        else
                        {
                            InsertText( !Input.IsShiftDown()
                                        ? char.ToLower( glyph )
                                        : glyph );
                        }
                    }
                    else if ( char.IsDigit( glyph ) )
                    {
                        if ( !Input.IsShiftDown() )
                            InsertText( glyph );
                        else
                            InsertText( ")[email protected]#$%^&*(".ElementAt( glyph - '0' ) );
                    }
                    break;

                case Keys.OemTilde:
                    InsertText( !Input.IsShiftDown() ? "`" : "~" );
                    break;

                case Keys.OemMinus:
                    InsertText( !Input.IsShiftDown() ? "-" : "_" );
                    break;

                case Keys.OemPlus:
                    InsertText( !Input.IsShiftDown() ? "=" : "+" );
                    break;

                case Keys.OemOpenBrackets:
                    InsertText( !Input.IsShiftDown() ? "[" : "{" );
                    break;

                case Keys.OemCloseBrackets:
                    InsertText( !Input.IsShiftDown() ? "]" : "}" );
                    break;

                case Keys.OemPipe:
                    InsertText( !Input.IsShiftDown() ? "\\" : "|" );
                    break;

                case Keys.OemSemicolon:
                    InsertText( !Input.IsShiftDown() ? ";" : ":" );
                    break;

                case Keys.OemQuotes:
                    InsertText( !Input.IsShiftDown() ? "'" : "\"" );
                    break;

                case Keys.OemComma:
                    InsertText( !Input.IsShiftDown() ? "," : "<" );
                    break;

                case Keys.OemPeriod:
                    InsertText( !Input.IsShiftDown() ? "." : ">" );
                    break;

                case Keys.OemQuestion:
                    InsertText( !Input.IsShiftDown() ? "/" : "?" );
                    break;
                }

                mIsSelecting = false;
            }

            if ( oldText != Text || oldInputPos != InputPos )
            {
                mCursorVisible = true;
                mLastCursorBlink = currMillis;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Opens the game console.
        /// </summary>
        /// <param name="closeKey"><para>The key that should close the game console.</para>
        /// <para>If the close key is set to null, the console can only be closed by call the <c>Close</c>-Method
        /// or if the user enters the <c>close</c> command and hits enter.</para></param>
        public void Open(Keys? closeKey)
        {
            if (!IsOpen && !IsOpening && !IsClosing) {
                if (Opening != null) {
                    CancelEventArgs cancelArgs = new CancelEventArgs();
                    Opening(this, cancelArgs);
                    if (cancelArgs.Cancel) {
                        return;
                    }
                }

                this._closeKey = closeKey;

                InitializeAnimation(OpeningAnimation, _openingAnimationTime);

                Enabled = Visible = true;
                IsOpening = true;
                IsClosing = false;
            }
        }
Exemplo n.º 14
0
 public KeySet(Keys? key, int initTime, int repeatPeriod)
 {
     this.assigned = key;
     this.initTime = initTime;
     this.repeatPeriod = repeatPeriod;
 }
Exemplo n.º 15
0
 public void Set(Keys value)
 {
     _value = value;
 }
Exemplo n.º 16
0
 public void Unset()
 {
     _value = null;
 }
Exemplo n.º 17
0
        internal void UpdateOpen()
        {
            oldState = currentState;
            currentState = Keyboard.GetState();

            underscoreCounter += Engine.DeltaTime;
            while (underscoreCounter >= UNDERSCORE_TIME)
            {
                underscoreCounter -= UNDERSCORE_TIME;
                underscore = !underscore;
            }

            if (repeatKey.HasValue)
            {
                if (currentState[repeatKey.Value] == KeyState.Down)
                {
                    repeatCounter += Engine.DeltaTime;

                    while (repeatCounter >= REPEAT_DELAY)
                    {
                        HandleKey(repeatKey.Value);
                        repeatCounter -= REPEAT_EVERY;
                    }
                }
                else
                    repeatKey = null;
            }

            foreach (Keys key in currentState.GetPressedKeys())
            {
                if (oldState[key] == KeyState.Up)
                {
                    HandleKey(key);
                    break;
                }
            }
        }
Exemplo n.º 18
0
        private void HandleKey(Keys key)
        {
            if (key != Keys.Tab && key != Keys.LeftShift && key != Keys.RightShift && key != Keys.RightAlt && key != Keys.LeftAlt && key != Keys.RightControl && key != Keys.LeftControl)
                tabIndex = -1;

            if (key != Keys.OemTilde && key != Keys.Enter && repeatKey != key)
            {
                repeatKey = key;
                repeatCounter = 0;
            }

            switch (key)
            {
                default:
                    if (key.ToString().Length == 1)
                    {
                        if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                            currentText += key.ToString();
                        else
                            currentText += key.ToString().ToLower();
                    }
                    break;

                case (Keys.D1):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '!';
                    else
                        currentText += '1';
                    break;
                case (Keys.D2):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '@';
                    else
                        currentText += '2';
                    break;
                case (Keys.D3):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '#';
                    else
                        currentText += '3';
                    break;
                case (Keys.D4):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '$';
                    else
                        currentText += '4';
                    break;
                case (Keys.D5):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '%';
                    else
                        currentText += '5';
                    break;
                case (Keys.D6):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '^';
                    else
                        currentText += '6';
                    break;
                case (Keys.D7):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '&';
                    else
                        currentText += '7';
                    break;
                case (Keys.D8):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '*';
                    else
                        currentText += '8';
                    break;
                case (Keys.D9):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '(';
                    else
                        currentText += '9';
                    break;
                case (Keys.D0):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += ')';
                    else
                        currentText += '0';
                    break;
                case (Keys.OemComma):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '<';
                    else
                        currentText += ',';
                    break;
                case (Keys.OemPeriod):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '>';
                    else
                        currentText += '.';
                    break;
                case (Keys.OemQuestion):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '?';
                    else
                        currentText += '/';
                    break;
                case (Keys.OemSemicolon):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += ':';
                    else
                        currentText += ';';
                    break;
                case (Keys.OemQuotes):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '"';
                    else
                        currentText += '\'';
                    break;
                case (Keys.OemBackslash):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '|';
                    else
                        currentText += '\\';
                    break;
                case (Keys.OemOpenBrackets):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '{';
                    else
                        currentText += '[';
                    break;
                case (Keys.OemCloseBrackets):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '}';
                    else
                        currentText += ']';
                    break;
                case (Keys.OemMinus):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '_';
                    else
                        currentText += '-';
                    break;
                case (Keys.OemPlus):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                        currentText += '+';
                    else
                        currentText += '=';
                    break;

                case (Keys.Space):
                    currentText += " ";
                    break;
                case (Keys.Back):
                    if (currentText.Length > 0)
                        currentText = currentText.Substring(0, currentText.Length - 1);
                    break;
                case (Keys.Delete):
                    currentText = "";
                    break;

                case (Keys.Up):
                    if (seekIndex < commandHistory.Count - 1)
                    {
                        seekIndex++;
                        currentText = string.Join(" ", commandHistory[seekIndex]);
                    }
                    break;
                case (Keys.Down):
                    if (seekIndex > -1)
                    {
                        seekIndex--;
                        if (seekIndex == -1)
                            currentText = "";
                        else
                            currentText = string.Join(" ", commandHistory[seekIndex]);
                    }
                    break;

                case (Keys.Tab):
                    if (currentState[Keys.LeftShift] == KeyState.Down || currentState[Keys.RightShift] == KeyState.Down)
                    {
                        if (tabIndex == -1)
                        {
                            tabSearch = currentText;
                            FindLastTab();
                        }
                        else
                        {
                            tabIndex--;
                            if (tabIndex < 0 || (tabSearch != "" && sorted[tabIndex].IndexOf(tabSearch) != 0))
                                FindLastTab();
                        }
                    }
                    else
                    {
                        if (tabIndex == -1)
                        {
                            tabSearch = currentText;
                            FindFirstTab();
                        }
                        else
                        {
                            tabIndex++;
                            if (tabIndex >= sorted.Count || (tabSearch != "" && sorted[tabIndex].IndexOf(tabSearch) != 0))
                                FindFirstTab();
                        }
                    }
                    if (tabIndex != -1)
                        currentText = sorted[tabIndex];
                    break;

                case (Keys.Enter):
                    if (currentText.Length > 0)
                        EnterCommand();
                    break;

                case (Keys.OemTilde):
                    Open = false;
                    break;
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Create a new menu instance, including subscribing to keypresses and all.
        /// </summary>
        /// <param name="Title">The title of this menu</param>
        /// <param name="Hotkey">The hotkey which opens/closes this menu (null for no key)</param>
        public Menu(string MenuFilename, Keys? Hotkey)
        {
            // Set up member properties
            ActiveMenu = null; // Null if no menu active - otherwise, the currently active menu or submenu
            this.MenuFilename = MenuFilename;
            Submenus = new List<Submenu>();
            Actions = new List<MenuAction>();
            this.Hotkey = Hotkey;

            // Set up logic properties
            _isHotkeyPressed = false;

            // Subscribe to our main application...
            OutsideSimulatorApp.GetInstance().Subscribe(this);
        }