Exemple #1
0
        public void ReadKey(VirtualKey key, CorePhysicalKeyStatus keyStatus)
        {
            _lastReadTime = DateTime.Now;

            if (key.ToString() == "186")
            {
                _isSemiColonEntered = true;
            }

            if (key == VirtualKey.Shift)
            {
                _isShift = true;
            }
            else
            {
                char?character = Helper.ToChar(key, _isShift);
                if (character.HasValue)
                {
                    _msrData += character;
                }
                _isShift = false;
            }

            if (key.ToString() == "191" && _isSemiColonEntered)
            {
                _readMSRComplete    = true;
                _isSemiColonEntered = false;
            }
        }
Exemple #2
0
        private void AssignButton(GamepadButtons button, VirtualKey key)
        {
            switch (button)
            {
            case GamepadButtons.Aux1:
                aux1_button.Content = key.ToString();
                break;

            case GamepadButtons.Aux2:
                aux2_button.Content = key.ToString();
                break;

            case GamepadButtons.Aux3:
                aux3_button.Content = key.ToString();
                break;

            case GamepadButtons.Aux4:
                aux4_button.Content = key.ToString();
                break;

            default:
                return;
            }

            this.assignedButtons[button] = key;
            SettingsManager.Instance.SaveButtonAssignment(this.assignedGamepadButton, key);
        }
Exemple #3
0
 public void Render()
 {
     ImGui.PushID(UUID.ToString());
     if (!waitingForKey)
     {
         var str = $"Binding: ";
         if (key != VirtualKey.NO_KEY)
         {
             str += $"{key.ToString()}";
         }
         else
         {
             str += "Unbound";
         }
         if (ImGui.Button(str))
         {
             waitingForKey = true;
         }
         ImGui.SameLine();
         if (ImGui.Button("Clear Binding"))
         {
             key = VirtualKey.NO_KEY;
         }
     }
     else
     {
         WaitForKey();
         var buf = "Waiting for Key";
         ImGui.Text(buf);
     }
     ImGui.PopID();
 }
        public GadgetHotkey(string setSettingsName, string labelText, FlowLayoutPanel flowLayoutPanel, Action setAction)
        {
            settingsName = setSettingsName;
            FlowLayoutPanel container = new FlowLayoutPanel()
            {
                AutoSize = true
            };

            hotkeyTextBox = new TextBox()
            {
                Width = 80, Margin = new Padding(0, 0, 20, 5)
            };
            Label hotkeyLabel = new Label()
            {
                Text = labelText
            };

            hotkeyAction = setAction;

            Key = (VirtualKey)(int)Properties.Settings.Default[settingsName];
            if (Key == VirtualKey.Escape)
            {
                hotkeyTextBox.Text = "Unbound";
            }
            else
            {
                hotkeyTextBox.Text = Key.ToString();
            }
            hotkeyTextBox.Enter += new EventHandler(enter);
            hotkeyTextBox.Leave += new EventHandler(leave);
            hotkeyTextBox.KeyUp += new KeyEventHandler(keyUp);
            container.Controls.Add(hotkeyTextBox);
            container.Controls.Add(hotkeyLabel);
            flowLayoutPanel.Controls.Add(container);
        }
Exemple #5
0
        void ConcatVirtualKey(VirtualKey key, ref string keyboardAcceleratorString)
        {
            string keyName;

            // UNO TODO
            //(DXamlCore.GetCurrent().GetLocalizedResourceString(GetResourceStringIdFromVirtualKey(key), keyName.ReleaseAndGetAddressOf()));
            keyName = key.ToString();


            if (string.IsNullOrEmpty(keyboardAcceleratorString))
            {
                // If this is the first key string we've accounted for, then
                // we can just set the keyboard accelerator string equal to it.
                keyboardAcceleratorString = keyName;
            }
            else
            {
                // Otherwise, if we already had an existing keyboard accelerator string,
                // then we'll use the formatting string to join strings together
                // to combine it with the new key string.
                string joiningFormatString;
                // UNO TODO
                // (DXamlCore.GetCurrent().GetLocalizedResourceString(KEYBOARD_ACCELERATOR_TEXT_JOIN, joiningFormatString.ReleaseAndGetAddressOf()));
                joiningFormatString = "{0} + {1}";

                keyboardAcceleratorString = string.Format(CultureInfo.InvariantCulture, joiningFormatString, keyboardAcceleratorString, keyName);
            }
        }
Exemple #6
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            VirtualKey src = (VirtualKey)value;
            string     key = src.ToString();

            return(key);
        }
Exemple #7
0
        public static string ToStringRepresentation(this VirtualKey key)
        {
            var stringRepresentation = string.Empty;

            stringRepresentation = Enum.GetName(typeof(VirtualKey), key);

            if (string.IsNullOrWhiteSpace(stringRepresentation))
            {
                _virtualKeyStringMap.TryGetValue(key.ToString(), out stringRepresentation);
            }

            return(stringRepresentation);
        }
Exemple #8
0
        public static KeyEventArgs VirtualKeyToKeyEvent(VirtualKey key, bool handled, bool isDown)
        {
            var currentKey = VirtualKeyToModifier(key);

            if (currentKey != KeyModifiers.None)
            {
                _keyModifiers = isDown ? SetKeyModifiers(currentKey) : ClearKeyModifiers(currentKey);
            }

            return(new KeyEventArgs {
                Key = key.ToString(), Handled = handled, Modifiers = _keyModifiers
            });
        }
Exemple #9
0
        Brush SpecialKeyDetector(VirtualKey myKey)
        {
            SolidColorBrush brush;

            if (myKey.ToString().Length == 1)
            {
                brush = new SolidColorBrush(Colors.LimeGreen);
            }
            else
            {
                brush = new SolidColorBrush(Colors.Red);
            }
            return(brush);
        }
Exemple #10
0
        private string VirtualKeyToLetterOnNorwegianKeyboard(VirtualKey key)
        {
            switch (key.ToString())
            {
            case "222":
                return("Æ");

            case "186":
                return("Ø");

            case "192":
                return("Ø");

            case "219":
                return("Å");

            case "221":
                return("Å");

            default:
                return(key.ToString());
            }
        }
 private void keyUp(object sender, KeyEventArgs e)
 {
     Key = (VirtualKey)e.KeyValue;
     if (Key == VirtualKey.Escape)
     {
         hotkeyTextBox.Text = "Unbound";
     }
     else
     {
         hotkeyTextBox.Text = Key.ToString();
     }
     e.Handled = true;
     hotkeyTabPage.Focus();
 }
Exemple #12
0
        private void keyUp(object sender, KeyEventArgs e)
        {
            var selectedTextBox = sender as TextBox;

            Key = (VirtualKey)e.KeyValue;
            if (Key == VirtualKey.Escape)
            {
                hotkeyTextBox.Text = "Unbound";
            }
            else
            {
                hotkeyTextBox.Text = Key.ToString();
            }
            e.Handled = true;
            selectedTextBox.Parent.Focus();
        }
        public GadgetHotkey(string setSettingsName, TextBox setTextBox, TabPage setTabPage, Action setAction)
        {
            settingsName  = setSettingsName;
            hotkeyTextBox = setTextBox;
            hotkeyTabPage = setTabPage;
            hotkeyAction  = setAction;

            Key = (VirtualKey)(int)Properties.Settings.Default[settingsName];
            if (Key == VirtualKey.Escape)
            {
                hotkeyTextBox.Text = "Unbound";
            }
            else
            {
                hotkeyTextBox.Text = Key.ToString();
            }

            hotkeyTextBox.Enter += new EventHandler(enter);
            hotkeyTextBox.Leave += new EventHandler(leave);
            hotkeyTextBox.KeyUp += new KeyEventHandler(keyUp);
        }
Exemple #14
0
 private unsafe static IntPtr LLKeyboardCallback(int nCode, KeyboardButtonsState wParam, KeyBoardLowlevelHookStruct *lParam)
 {
     if (nCode > -1)
     {
         KeyBoardLowlevelHookStruct hookStruct = *lParam;
         VirtualKey key = hookStruct.VkCode;
         if (key == VirtualKey.LShift)
         {
             LShiftPress = (wParam == KeyboardButtonsState.WM_KEYDOWN);
         }
         if (key == VirtualKey.RShift)
         {
             RShiftPress = (wParam == KeyboardButtonsState.WM_KEYDOWN);
         }
         if (key == VirtualKey.CapsLock)
         {
             CapsPressed = (wParam == KeyboardButtonsState.WM_KEYDOWN);
         }
         string v = (LShiftPress || RShiftPress || CapsPressed) ? key.ToString() : key.ToString().ToLower();
         KeyboardEvent.Invoke(v, wParam, hookStruct);
     }
     return(User32.CallNextHookEx(KBHook, nCode, (IntPtr)wParam, (IntPtr)lParam));
 }
Exemple #15
0
        private decimal GetDigitFromKey(VirtualKey key)
        {
            switch (key)
            {
            case VirtualKey.Number0:
            case VirtualKey.NumberPad0: return(0M);

            case VirtualKey.Number1:
            case VirtualKey.NumberPad1: return(1M);

            case VirtualKey.Number2:
            case VirtualKey.NumberPad2: return(2M);

            case VirtualKey.Number3:
            case VirtualKey.NumberPad3: return(3M);

            case VirtualKey.Number4:
            case VirtualKey.NumberPad4: return(4M);

            case VirtualKey.Number5:
            case VirtualKey.NumberPad5: return(5M);

            case VirtualKey.Number6:
            case VirtualKey.NumberPad6: return(6M);

            case VirtualKey.Number7:
            case VirtualKey.NumberPad7: return(7M);

            case VirtualKey.Number8:
            case VirtualKey.NumberPad8: return(8M);

            case VirtualKey.Number9:
            case VirtualKey.NumberPad9: return(9M);

            default: throw new ArgumentOutOfRangeException("Invalid key: " + key.ToString());
            }
        }
Exemple #16
0
        /// <summary>
        /// Called when [key down].
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="reset">if set to <c>true</c> [reset].</param>
        private void OnKeyDown(VirtualKey key, bool reset)
        {
            if (!this.assigning)
            {
                return;
            }

            lock (this.clickLock)
            {
                if (this.assigning)
                {
                    this.assignedButtons[this.assignedGamepadButton] = key;
                    this.assignedButton.Content = key.ToString();

                    // Workaround that certain characters get captured twice
                    this.deferringClear = !reset;
                    if (reset)
                    {
                        this.EnableButtons();
                        this.ClearAssignmentVariables();
                    }
                }
            }
        }
Exemple #17
0
        /// <summary>
        /// Called when [key down].
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="reset">if set to <c>true</c> [reset].</param>
        private void OnKeyDown(VirtualKey key, bool reset)
        {
            if (!this.assigning)
            {
                return;
            }

            lock (this.clickLock)
            {
                if (this.assigning)
                {
                    this.assignedButtons[this.assignedGamepadButton] = key;
                    this.assignedButton.Content = key.ToString();

                    // Workaround that certain characters get captured twice 
                    this.deferringClear = !reset;
                    if (reset)
                    {
                        this.EnableButtons();
                        this.ClearAssignmentVariables();
                    }
                }
            }
        }
Exemple #18
0
        // Filters text according to numeric type
        private string FilterText(string text, VirtualKey key, KeyRoutedEventArgs e)
        {
            // Apart from Number, Decimal point and negative neglect everything

            switch (NumericKeyType)
            {
            case NumericKeyType.Number:
                if (_isShiftPressed ||
                    !key.ToString().StartsWith(_number))
                {
                    e.Handled = true;
                    return(text);
                }
                break;

            case NumericKeyType.Amount:
                if (_isShiftPressed ||
                    (!key.ToString().StartsWith(_number) &&
                     (key.ToString() != _decimal && key != VirtualKey.Decimal) &&
                     (key.ToString() != _negativeSign && key != VirtualKey.Subtract)))
                {
                    e.Handled = true;
                    return(text);
                }
                break;

            case NumericKeyType.Card:
                if (_isShiftPressed && key.ToString() == _questionMark)
                {
                    break;
                }

                if (_isShiftPressed ||
                    (!key.ToString().StartsWith(_number) &&
                     (key.ToString() != _decimal && key != VirtualKey.Decimal) &&
                     (key.ToString() != _negativeSign && key != VirtualKey.Subtract) &&
                     key.ToString() != _semiColon &&
                     key.ToString() != _equalSign))
                {
                    e.Handled = true;
                    return(text);
                }
                break;

            case NumericKeyType.StockCodeNumber:
                if (_isShiftPressed && key.ToString() == _questionMark)
                {
                    break;
                }

                if (key.ToString() == _semiColon)
                {
                    e.Handled = true;
                    return(text);
                }
                break;

            default:
                break;
            }


            // If negative is pressed in between then also ignore it
            if (NumericKeyType != NumericKeyType.StockCodeNumber)
            {
                if (SelectionStart != 0 && key.ToString() == _negativeSign)
                {
                    e.Handled = true;
                    return(text);
                }
            }

            // Discard any second decimal point
            if (text.Count(x => x == '.') > 0 && key.ToString() == _decimal)
            {
                e.Handled = true;
                return(text);
            }
            return(text);
        }
Exemple #19
0
 public static Key VirtualKeyToKey(VirtualKey virtualKey)
 {
     return((Key)System.Enum.Parse(typeof(Key), virtualKey.ToString()));
 }
Exemple #20
0
 public void SaveButtonAssignment(GamepadButtons button, VirtualKey assignment)
 {
     settings.Values[button.ToString()] = assignment.ToString();
 }
 private string GetKeyValue(VirtualKey key)
 {
     if (key >= VirtualKey.Number0 & key <= VirtualKey.Number9)
     {
         return key.ToString().Replace("Number", "");
     }
     return key.ToString();
 }
Exemple #22
0
        private void ChangeText(VirtualKey key)
        {
            if (this._keyText == null)
            {
                return;
            }

            string text, side;
            Symbol?symbol = null;

            switch (key)
            {
            case VirtualKey.LeftShift:
                text = "Shift";
                side = "Left";
                break;

            case VirtualKey.RightShift:
                text = "Shift";
                side = "Right";
                break;

            case VirtualKey.LeftMenu:
                text = "Alt";
                side = "Left";
                break;

            case VirtualKey.RightMenu:
                text = "Alt";
                side = "Right";
                break;

            case VirtualKey.LeftControl:
                text = "Ctrl";
                side = "Left";
                break;

            case VirtualKey.RightControl:
                text = "Ctrl";
                side = "Right";
                break;

            case VirtualKey.LeftWindows:
                text = "Win";
                side = "Left";
                break;

            case VirtualKey.RightWindows:
                text = "Win";
                side = "Right";
                break;

            case VirtualKey.Up:
                text   = "";
                side   = "";
                symbol = Symbol.Up;
                break;

            case VirtualKey.Left:
                text   = "";
                side   = "";
                symbol = Symbol.Back;
                break;

            case VirtualKey.Right:
                text   = "";
                side   = "";
                symbol = Symbol.Forward;
                break;

            default:
                text = key.ToString();
                side = "";
                break;
            }

            if (this._keyText != null)
            {
                this._keyText.Text       = text;
                this._keyText.Visibility = string.IsNullOrEmpty(text) ? Visibility.Collapsed : Visibility.Visible;
            }

            if (this._rightOrLeftText != null)
            {
                this._rightOrLeftText.Text       = side;
                this._rightOrLeftText.Visibility = string.IsNullOrEmpty(side) ? Visibility.Collapsed : Visibility.Visible;
            }

            if (this._symbol != null)
            {
                if (symbol.HasValue)
                {
                    this._symbol.Symbol     = symbol.Value;
                    this._symbol.Visibility = Visibility.Visible;
                }
                else
                {
                    this._symbol.Visibility = Visibility.Collapsed;
                }
            }
        }
Exemple #23
0
 /// <summary>
 /// Convert to string.
 /// </summary>
 /// <returns>Returns string representation of this key, if not possible empty string is returned.</returns>
 public override string ToString()
 {
     return($"{Enum.GetName(VirtualKey) ?? VirtualKey.ToString()} - {IsSystemKey}");
 }