示例#1
0
        private static LogicalKey CreateKey(VirtualKeyCode keyCode, IInputSimulator inputSimulator, KeyBehaviour keyType, VirtualKeyCollection chordKeys, string outputText)
        {
            LogicalKey result = null;

            switch (keyType)
            {
            case KeyBehaviour.VirtualKey:
                result = CreateVirtualKey(keyCode, inputSimulator);
                break;

            case KeyBehaviour.Chord:
                result = CreateChordKey(keyCode, inputSimulator, chordKeys);
                break;

            case KeyBehaviour.Text:
                result = CreateTextKey(keyCode, inputSimulator, outputText);
                break;

            case KeyBehaviour.InstantaneousModifier:
                result = CreateInstantaneousModifierKey(keyCode, inputSimulator);
                break;

            case KeyBehaviour.TogglingModifier:
                result = CreateTogglingModifierKey(keyCode, inputSimulator);
                break;

            default:
                break;
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Processes the event from a child control when is has been clicked.  The logical
        /// key that is associated with the child control is obtained and its "ScreenKeyPress"
        /// method is called.
        /// </summary>
        /// <param name="keyboardElement"></param>
        private void ProcessGenericKeyPress(UIElement keyboardElement)
        {
            if (!keys.ContainsKey(keyboardElement))
            {
                return;
            }

            LogicalKey key = keys[keyboardElement];

            key.ScreenKeyPress();
        }
示例#3
0
        private static void RecreateKey(UIElement child)
        {
            if (child == null)
            {
                return;
            }

            if (!(VisualTreeHelper.GetParent(child) is Keyboard parentKeyboard) || parentKeyboard.keys == null)
            {
                return;
            }

            // make sure key exist. If it's behavour is none it will not exist
            if (parentKeyboard.keys.ContainsKey(child))
            {
                LogicalKey oldKey = parentKeyboard.keys[child];

                parentKeyboard.keys.Remove(child);
                parentKeyboard.modifierKeys.Remove(oldKey as ModifierKeyBase);
            }

            VirtualKeyCode       keyCode      = (VirtualKeyCode)child.GetValue(KeyCodeProperty);
            KeyBehaviour         keyBehaviour = (KeyBehaviour)child.GetValue(KeyBehaviourProperty);
            VirtualKeyCollection chordKeys    = (VirtualKeyCollection)child.GetValue(ChordKeysProperty);
            string outputText = (string)child.GetValue(OutputTextProperty);

            if (keyBehaviour == KeyBehaviour.None)
            {
                // do not create a new key
                return;
            }

            LogicalKey key = CreateKey(keyCode, parentKeyboard.inputSimulator, keyBehaviour, chordKeys, outputText);

            if (key == null)
            {
                return;
            }

            parentKeyboard.keys.Add(child, key);
            key.KeyPressed += parentKeyboard.LogicalKeyPressed;

            if (keyBehaviour == KeyBehaviour.InstantaneousModifier || keyBehaviour == KeyBehaviour.TogglingModifier)
            {
                parentKeyboard.modifierKeys.Add(key as ModifierKeyBase);
            }
        }
示例#4
0
        public override void EndInit()
        {
            inputSimulator = CreateInputSimulator();
            keys           = new Dictionary <UIElement, LogicalKey>();
            modifierKeys   = new List <ModifierKeyBase>();

            foreach (UIElement child in Children)
            {
                VirtualKeyCode       keyCode      = (VirtualKeyCode)child.GetValue(KeyCodeProperty);
                KeyBehaviour         keyBehaviour = (KeyBehaviour)child.GetValue(KeyBehaviourProperty);
                VirtualKeyCollection chordKeys    = (VirtualKeyCollection)child.GetValue(ChordKeysProperty);
                string outputText = (string)child.GetValue(OutputTextProperty);

                if (keyBehaviour == KeyBehaviour.None)
                {
                    // skip to the next child element
                    continue;
                }

                LogicalKey key = CreateKey(keyCode, inputSimulator, keyBehaviour, chordKeys, outputText);
                if (key == null)
                {
                    // skip to the next child element
                    continue;
                }

                ConnectToChildControl(child);
                keys.Add(child, key);
                key.KeyPressed += LogicalKeyPressed;

                if (keyBehaviour == KeyBehaviour.InstantaneousModifier || keyBehaviour == KeyBehaviour.TogglingModifier)
                {
                    modifierKeys.Add(key as ModifierKeyBase);
                }
            }

            SynchroniseModifierKeyState();
            base.EndInit();
        }