Ejemplo n.º 1
1
        // Compares the key which was pressed with a target key.
        // If they are the same, updates a label which keeps track
        // of the number of times the target key has been pressed.
        private void SourceTextKeyDown(object sender, KeyEventArgs e)
        {
            // The key converter.
            var converter = new KeyConverter();
            var target = Key.None;

            // Verifying there is only one character in the string.
            if (txtTargetKey.Text.Length == 1)
            {
                // Converting the string to a Key.
                target = (Key) converter.ConvertFromString(txtTargetKey.Text);
            }

            // If the pressed key is equal to the target key. 
            if (e.Key == target)
            {
                // Incrementing  the number of hits, and updating
                // the label which displays the number of hits.
                _numberOfHits++;
                lblNumberOfTargetHits.Content = _numberOfHits;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the back.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="culture">The culture.</param>
        /// <returns>object</returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            KeyConverter kc = new KeyConverter();
              ObservableCollection<Key> c = new ObservableCollection<Key>();
              String v = (String)value;
              string[] ss = v.Split('+');

              if (ss.Length == 0)
            return c;

              foreach (string s in ss)
              {
            s.Trim();
            c.Add((Key)kc.ConvertFromString(s));
              }

              return c;
        }
Ejemplo n.º 3
0
        private static void LoadCustomKeysFromFile()
        {
            /*
            comboKey
            revealKey
            toogleAutoUltKey
            decreaseSurroundingAlliesKey -- not customizable
            increaseSurroundingAlliesKey -- not customizable
            */
            if (File.Exists(@"C:\VengeKeys.txt"))
            {
                using (StreamReader sr = new StreamReader(@"C:\VengeKeys.txt"))
                {
                    int i = 1;
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        KeyConverter keyConverter = new KeyConverter();
                        Key ownKey = (Key)keyConverter.ConvertFromString(line);

                        switch (i)
                        {
                            case 1:
                                comboKey = ownKey;
                                break;
                            case 2:
                                revealKey = ownKey;
                                break;
                            case 3:
                                toogleAutoUltKey = ownKey;
                                break;
                        }

                        i++;
                    }
                    sr.Close();
                }
            }
        }
Ejemplo n.º 4
0
        private void WriteAlphaNumericToActiveControl(string key)
        {
            if (this._activeControl == null)
            {
                return;
            }
            this._activeControl.Focus();

            var textEvent = new TextCompositionEventArgs(Keyboard.PrimaryDevice,
                                                         new TextComposition(InputManager.Current, Keyboard.FocusedElement, key))
            {
                RoutedEvent = TextInputEvent
            };

            InputManager.Current.ProcessInput(textEvent);

            try
            {
                Key theKey = (Key)keyConverter.ConvertFromString(key);
                if (Keyboard.PrimaryDevice.ActiveSource == null)
                {
                    return;
                }
                var keyEvent = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, theKey)
                {
                    RoutedEvent = Keyboard.KeyDownEvent
                };
                if (OnButtonClick != null)
                {
                    OnButtonClick(this, keyEvent);
                }
            }
            catch (System.ArgumentException ex)
            {
                //Hay caracteres que no corresponden a teclado no se
            }
        }
Ejemplo n.º 5
0
 public void KeyUnPressed(object o, KeyEventArgs e)
 {
     var convert = new KeyConverter();
     if (e.Key == (Key)convert.ConvertFromString(keybindings.Toggle))
     {
         isManualPressed = false;
     }
 }
Ejemplo n.º 6
0
        ////////////////////////////////////////////////////////////////////////
        ///
        /// @fn void EditorController::KeyPressed()
        ///
        /// Cette fonction bind des touche du clavier à des actions
        ///
        /// @param[in] o : celui qui a envoyé l'action
        /// @param[in] e : Les données de l'événement
        /// 
        /// @return Aucun
        ///
        ////////////////////////////////////////////////////////////////////////
        public void KeyPressed(object o, KeyEventArgs e)
        {
            var convert = new KeyConverter();

            if (e.Key == Key.Left)
            {
                Debug.Write("Deplacement camera gauche");
                engine.deplacerXY(-0.10, 0.0);
            }
            else if (e.Key == Key.Right)
            {
                Debug.Write("Deplacement camera droite");
                engine.deplacerXY(0.10, 0.0);
            }
            else if (e.Key == Key.Up)
            {
                Debug.Write("Deplacement camera haut");
                engine.deplacerXY(0.0, 0.10);
            }
            else if (e.Key == Key.Down)
            {
                Debug.Write("Deplacement camera bas");
                engine.deplacerXY(0.0, -0.10);
            }
            else if (e.Key == Key.OemMinus || e.Key == Key.Subtract)
            {
                Debug.Write("ZoomOut");
                engine.zoomerOut();
            }
            else if (e.Key == Key.OemPlus || e.Key == Key.Add)
            {
                Debug.Write("ZoomIN");
                engine.zoomerIn();
            }
            else if (e.Key == Key.J && modeTestEnabled)
            {
               engine.toggleAmbiante();
            }
            else if (e.Key == Key.K && modeTestEnabled)
            {
                engine.toggleDirectional();
            }
            else if (e.Key == Key.L && modeTestEnabled)
            {
                engine.toggleSpots();
            }
            else if (e.Key == Key.Escape)
            {
                toolContext.esc();
            }
            else if (e.Key == Key.A && System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Control)
            {
                engine.selectAll();
            }
            else if (modeTestEnabled && e.Key == (Key)convert.ConvertFromString(keybindings.Toggle) && !isManualPressed)
            {
                 engine.robotToggleManualControl();
                 manualModeEnabled = !manualModeEnabled;
                 isManualPressed = true;
            }
        }
Ejemplo n.º 7
0
        ////////////////////////////////////////////////////////////////////////
        ///
        /// @fn void EditorController::DetectUserInput()
        ///
        /// Cette fonction détacte quand on actionne une touche du mode manuel.
        /// 
        /// @return Aucun
        ///
        ////////////////////////////////////////////////////////////////////////
        public void DetectUserInput()
        {
            if (modeTestEnabled)
            {
                var convert = new KeyConverter();

                if (manualModeEnabled == true)
                {
                    if (Keyboard.IsKeyDown((Key)convert.ConvertFromString(keybindings.Forward)))
                    {
                        engine.robotForward();
                    }
                    if (Keyboard.IsKeyDown((Key)convert.ConvertFromString(keybindings.Reverse)))
                    {
                        engine.robotReverse();
                    }
                    if (Keyboard.IsKeyDown((Key)convert.ConvertFromString(keybindings.TurnLeft)))
                    {
                        engine.playSoundTurn(false);
                        engine.robotTurnLeft();
                    }
                    if (Keyboard.IsKeyDown((Key)convert.ConvertFromString(keybindings.TurnRight)))
                    {
                        engine.playSoundTurn(false);
                        engine.robotTurnRight();
                    }
                    if (!Keyboard.IsKeyDown((Key)convert.ConvertFromString(keybindings.TurnRight)) &&
                        (!Keyboard.IsKeyDown((Key)convert.ConvertFromString(keybindings.TurnLeft))))
                    {
                        engine.playSoundTurn(true);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private List<List<VirtualKeyCode>> processKeyboardShortcutAsString(string shortcut) {
     List<List<VirtualKeyCode>> result = new List<List<VirtualKeyCode>>();
     List<VirtualKeyCode> listModifiers = new List<VirtualKeyCode>();
     List<VirtualKeyCode> listKey = new List<VirtualKeyCode>();
     if (shortcut.Contains("Ctrl")) {
         listModifiers.Add(VirtualKeyCode.CONTROL);
         shortcut = shortcut.Replace("Ctrl", "");
     }
     if (shortcut.Contains("Shift")) {
         listModifiers.Add(VirtualKeyCode.SHIFT);
         shortcut = shortcut.Replace("Shift", "");
     }
     if (shortcut.Contains("Alt")) {
         listModifiers.Add(VirtualKeyCode.MENU);
         shortcut = shortcut.Replace("Alt", "");
     }
     if (shortcut.Contains("Win")) {
         listModifiers.Add(VirtualKeyCode.LWIN);
         shortcut = shortcut.Replace("Win", "");
     }
     shortcut = shortcut.Replace("+", "");
     KeyConverter k = new KeyConverter();
     Key key = (Key)k.ConvertFromString(shortcut);
     listKey.Add((VirtualKeyCode)KeyInterop.VirtualKeyFromKey(key));
     result.Add(listModifiers);
     result.Add(listKey);
     return result;
 }
Ejemplo n.º 9
0
        private void InitlializeShortucts()
        {
            // shortcuts dictionary
            _shortcuts = new Dictionary<Tuple<Key, ModifierKeys>, Action>();

            // key converters
            var keyConverter = new KeyConverter();
            var modifiersKeyConverter = new ModifierKeysConverter();

            // open shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("O"),
                    (ModifierKeys)modifiersKeyConverter.ConvertFromString("Control")),
                () => Open());

            // save shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("S"),
                    (ModifierKeys)modifiersKeyConverter.ConvertFromString("Control")),
                () => Save());

            // export shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("E"),
                    (ModifierKeys)modifiersKeyConverter.ConvertFromString("Control")),
                () => Export());

            // undo shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("Z"),
                    (ModifierKeys)modifiersKeyConverter.ConvertFromString("Control")),
                () => _view.Undo());

            // redo shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("Y"),
                    (ModifierKeys)modifiersKeyConverter.ConvertFromString("Control")),
                () => _view.Redo());

            // snap shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("S"),
                    ModifierKeys.None),
                () => _view.ToggleSnap());

            // clear shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("Delete"),
                    (ModifierKeys)modifiersKeyConverter.ConvertFromString("Control")),
                () => _view.Clear());

            // editor shortcuts
            foreach (var editor in _view.Editors)
            {
                var _editor = editor;
                _shortcuts.Add(
                    new Tuple<Key, ModifierKeys>(
                        (Key)keyConverter.ConvertFromString(editor.Key),
                        editor.Modifiers == "" ? ModifierKeys.None : (ModifierKeys)modifiersKeyConverter.ConvertFromString(editor.Modifiers)),
                    () => _view.Enable(_editor));
            }

            // block shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("G"),
                    ModifierKeys.None),
                () => _view.CreateBlock());

            // delete shortcut
            _shortcuts.Add(
                new Tuple<Key, ModifierKeys>(
                    (Key)keyConverter.ConvertFromString("Delete"),
                    ModifierKeys.None),
                () => _view.Delete());
        }
Ejemplo n.º 10
0
		/// <summary>
		/// The callback for the keyboard hook
		/// </summary>
		/// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
		/// <param name="wParam">The event type</param>
		/// <param name="lParam">The keyhook event information</param>
		/// <returns></returns>
		public int hookProc(int code, int wParam, ref keyboardHookStruct lParam) {
            if (code >= 0) {
                
                char character = (char)lParam.vkCode;
                byte functional = (byte)lParam.scanCode;               

                Key key = Key.None;

                if ((lParam.vkCode > 47 && lParam.vkCode < 58) || (lParam.vkCode > 64 && lParam.vkCode < 92))
                {
                    string text = character.ToString();
                    KeyConverter k = new KeyConverter();
                    key = (Key)k.ConvertFromString(character.ToString());
                } else {
                    switch (lParam.vkCode){
                        case 27:
                            key = Key.Escape;
                        break;
                        case 37:
                            key = Key.Left;
                        break;
                        case 38:
                            key = Key.Up;
                        break;
                        case 39:
                            key = Key.Right;
                        break;
                        case 40:
                            key = Key.Down;
                        break;
                    }
                }

                    if (HookedKeys.Contains(key))
                    {
                        if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null))
                        {
                            KeyDown(this, key);
                            //return 1;
                        }
                        else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null))
                        {
                            KeyUp(this, key);
                            //return 1;
                        }
                    }
                
			}
			return CallNextHookEx(hhook, code, wParam, ref lParam);
		}