Exemplo n.º 1
0
        public void HandleKeyEvent(SemanticKey semanticKey, KeyPressDirection pressDirection)
        {
            var firstPressEvent = !pressedKeys.Remove(semanticKey);

            if (pressDirection == KeyPressDirection.Down)
                pressedKeys.Add(semanticKey);

            pressedKeys2 = pressedKeys.ToArray();

            var lshiftKey = new SemanticKey("ShiftL", null);
            var rshiftKey = new SemanticKey("ShiftR", null);

            if (semanticKey.Name == "MouseLeftClick")
            {
                var m = new WindowsMouse();
                if (pressDirection == KeyPressDirection.Down)
                    m.SetButtonState(MouseButton.Left, KeyPressDirection.Down);
                else
                    m.SetButtonState(MouseButton.Left, KeyPressDirection.Up);
                return;
            }

            KeyDefinition kd;
            if (semanticKey.Name != null && keyDefinitions.TryGetValue(semanticKey.Name, out kd))
            {
                var isShiftPressed = pressedKeys.Contains(lshiftKey) || pressedKeys.Contains(rshiftKey);
                var modifierMatch = true;
                if (kd.Modifiers != null)
                {
                    var set1 = new HashSet<QwertzModifier>(kd.Modifiers);
                    var set2 = new HashSet<QwertzModifier>();
                    if (isShiftPressed)
                        set2.Add(QwertzModifier.Shift);
                    modifierMatch = set1.SetEquals(set2);
                }

                if (kd.QwertzVirtualKeyCode != null && modifierMatch)
                    targetKeyboard.HandleKeyEvent(new Key((Keys)kd.QwertzVirtualKeyCode), pressDirection);
                else if (kd.Text != null)
                    targetKeyboard.HandleKeyEvent(new Key(kd.Text.First()), pressDirection);
            }
            else if (semanticKey.Text != null)
                targetKeyboard.HandleKeyEvent(new Key(semanticKey.Text.First()), pressDirection);
        }
Exemplo n.º 2
0
        public Layer GetLayer(SemanticKey[] pressedKeys)
        {
            var keys = pressedKeys.Intersect(ModifierKeys).ToList();
            while (true)
            {
                var hs1 = new HashSet<string>(keys.Select(k => k.Name));

                foreach (var layer in layers)
                {
                    foreach (var mk in layer.ModifierKeys)
                    {
                        var hs = new HashSet<string>(mk.Select(k => k.ToSemanticKey().Name));
                        if (hs1.SetEquals(hs))
                            return new Layer(layer.Name);
                    }
                }

                keys.Remove(keys.Last());
            }
        }
Exemplo n.º 3
0
 public void HandleKeyEvent(SemanticKey key, KeyPressDirection pressDirection)
 {
     Console.WriteLine(pressDirection + " " + key);
 }