示例#1
0
 public KeyboardState( params KeyboardKey [] keys )
     : this()
 {
     PressedKeys = new KeyboardKey [ keys.Length ];
     for ( int i = 0; i < keys.Length; i++ )
         PressedKeys [ i ] = keys [ i ];
 }
示例#2
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     AltCheckBox.Checked         = false;
     CrtlCheckBox.Checked        = false;
     ShiftCheckBox.Checked       = false;
     KeyActionRadioBtn.Checked   = true;
     TextActionRadioBtn.Checked  = false;
     MouseActionRadioBtn.Checked = false;
     KeyActionPanel.Visible      = true;
     TextActionPanel.Visible     = false;
     MouseActionPanel.Visible    = false;
     ActionComboBox.ResetText();
     MouseActionComboBox.ResetText();
     currentRowIndex    = e.RowIndex;
     currentColumnIndex = e.ColumnIndex;
     try
     {
         if (currentRowIndex >= 0 && currentColumnIndex >= 0)
         {
             ShowConfigPanel(true);
             var firstKey  = new KeyboardKey(Globals.NumericVirtualKeyCodes.ElementAt(currentRowIndex), KeyCombinationPosition.First);
             var SecondKey = new KeyboardKey(Globals.NumericVirtualKeyCodes.ElementAt(currentColumnIndex - 1), KeyCombinationPosition.Second);
             currentCombination        = new TwoKeysCombination();
             currentCombination.Keys   = new[] { firstKey, SecondKey };
             currentCombination.logger = logger;
         }
     }
     catch (ArgumentOutOfRangeException)
     {
         logger.Warn("Row cell clicked");
     }
 }
示例#3
0
        void keyPressedHelper(KeyboardKey sender)
        {
            var model = this.layout?.keyForView(sender);

            if (model != null)
            {
                this.keyPressed(model);

                // auto exit from special char subkeyboard;
                if (model.type == Key.KeyType.Space || model.type == Key.KeyType.Return)
                {
                    this.currentMode = 0;
                }
                else if (model.lowercaseOutput == "'")
                {
                    this.currentMode = 0;
                }
                else if (model.type == Key.KeyType.Character)
                {
                    this.currentMode = 0;
                }

                // auto period on double space;
                // TODO: timeout;

                this.handleAutoPeriod(model);
                // TODO: reset context;
            }

            this.setCapsIfNeeded();
        }
示例#4
0
        void UpdateInput()
        {
            UpdateMousePosAndButtons();
            UpdateMouseCursor();
            UpdateGamepads();

            int keyPressed = Raylib.GetKeyPressed();

            if (keyPressed > 0)
            {
                ImGuiIOPtr io = ImGui.GetIO();

                KeyboardKey[] nono = new KeyboardKey[]
                {
                    KeyboardKey.KEY_LEFT_SHIFT,
                    KeyboardKey.KEY_LEFT_ALT,
                    KeyboardKey.KEY_LEFT_CONTROL,
                    KeyboardKey.KEY_CAPS_LOCK,
                };

                if (!nono.Contains((KeyboardKey)keyPressed))
                {
                    io.AddInputCharacter((uint)(Encoding.UTF8.GetString(new byte[] { (byte)keyPressed })[0]));
                }
            }
        }
示例#5
0
        public void ApplyOnKeyUp(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed)
        {
            // Ensure the phrase is inserted at the end of a sentence or paragraph.
            bool atEndOfSentence = (thisKeyPress == KeyboardKey.Space) &&
                                   Array.IndexOf(KeyboardTables.EndOfSentenceCharacters, _LastLetterPressed) != -1;

            if (atEndOfSentence)
            {
                // Actually insert the phrase!!
                var s = _Phrases[_SelectedPhrase];
                for (int i = 0; i < s.Length; i++)
                {
                    var keyStroke = KeyboardTables.CharToKeyStroke(s[i]);
                    output.KeyPressWithModifier(keyStroke);
                }
                // Append a space.
                if (s[s.Length - 1] != ' ')
                {
                    output.KeyPress(KeyboardKey.Space);
                }

                // Mark completion.
                _IsComplete = true;
            }
            else
            {
                // Capture the last keypress as a character.
                var c = KeyboardTables.KeyToChar(thisKeyPress, isShifted);
                if (c != (char)0)
                {
                    _LastLetterPressed = c;
                }
            }
        }
 internal ArtemisKeyboardKeyEventArgs(ArtemisDevice?device, ArtemisLed?led, KeyboardKey key, KeyboardModifierKey modifiers)
 {
     Device    = device;
     Led       = led;
     Key       = key;
     Modifiers = modifiers;
 }
示例#7
0
        public void ApplyOnKeyUp(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed)
        {
            var now = Utility.GetMachineTime();

            // Exit conditions: exceeded the maximum delay OR user has delayed too long between key presses (and has probably noticed the delay).
            if (_CurrentDelay > _MaxDelay || now.Subtract(_LastDetectedKeyPress).CompareTo(_KeyPressDeltaToAbort) > 0)
            {
                _IsComplete = true;
                return;
            }

            // If this keypress corresponds to a typable character, queue a delay after it.
            var c = KeyboardTables.KeyToChar(thisKeyPress, isShifted);

            if (c != '\0')
            {
                output.Delay(_CurrentDelay);

                // Increment the current delay for the next keypress.
                _CurrentDelay += _DelayIncrement;
            }

            // Keep the time of the last key press for next call.
            _LastDetectedKeyPress = now;
        }
示例#8
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            var offset = 11 + Index * (26 + (int)_font.MeasureString(Text.Value).X);

            if (GameProvider.GameInstance.GetService <InputSystem>().GamePad.IsConnected())
            {
                spriteBatch.Draw(GetTexture(), new Rectangle(offset, GameProvider.GameInstance.ScreenBounds.Height - 48, 32, 32), _highlightColor);
                offset += 32;
            }
            else
            {
                int    boxWidth      = 32;
                string displayString = KeyboardKey.ToString();

                if (_font.MeasureString(displayString).X + 10 > 32)
                {
                    boxWidth = (int)(_font.MeasureString(displayString).X + 10);
                }

                GameProvider.GameInstance.GetService <ShapeRenderer>().DrawRectangle(new Rectangle(offset, GameProvider.GameInstance.ScreenBounds.Height - 48, boxWidth, 32), _highlightColor, filled: false);
                spriteBatch.DrawString(_font, displayString, new Vector2(offset + 5, GameProvider.GameInstance.ScreenBounds.Height - 48), _highlightColor);

                offset += boxWidth;
            }

            spriteBatch.DrawString(_font, Text.Value, new Vector2(offset + 10, GameProvider.GameInstance.ScreenBounds.Height - 48), _highlightColor);
        }
示例#9
0
 public MouseEventArgs(int x, int y, MouseButton button, KeyboardKey modificators)
 {
     X               = x;
     Y               = y;
     PressedButton   = button;
     KeyModificators = modificators;
 }
示例#10
0
        private void ActivateAndFocusMainWindow()
        {
            // What happens below looks a bit weird, but for Switcheroo to get focus when using the Alt+Tab hook,
            // it is needed to simulate an Alt keypress will bring Switcheroo to the foreground. Otherwise Switcheroo
            // will become the foreground window, but the previous window will retain focus, and receive keep getting
            // the keyboard input.
            // http://www.codeproject.com/Tips/76427/How-to-bring-window-to-top-with-SetForegroundWindo

            var thisWindowHandle = new WindowInteropHelper(this).Handle;
            var thisWindow       = new AppWindow(thisWindowHandle);

            var altKey        = new KeyboardKey(Keys.Alt);
            var altKeyPressed = false;

            // Press the Alt key if it is not already being pressed
            if ((altKey.AsyncState & 0x8000) == 0)
            {
                altKey.Press();
                altKeyPressed = true;
            }

            // Bring the Switcheroo window to the foreground
            Show();
            SystemWindow.ForegroundWindow = thisWindow;
            Activate();

            // Release the Alt key if it was pressed above
            if (altKeyPressed)
            {
                altKey.Release();
            }
        }
示例#11
0
        static public void Write(string text)
        {
            Random random = new Random();

            foreach (char c in text)
            {
                foreach (KeyboardKey kb_key in chars2key[c])
                {
                    Keyboard.KeyDown(kb_key);

                    pressed_stack.Push(kb_key);

                    Thread.Sleep(random.Next(25, 75));
                }

                while (pressed_stack.Count > 0)
                {
                    KeyboardKey kb_key = pressed_stack.Pop();

                    Keyboard.KeyUp(kb_key);

                    Thread.Sleep(random.Next(20, 50));
                }
            }
        }
示例#12
0
文件: Input.cs 项目: Corne66/Roro
 public static void KeyDown(KeyboardKey key)
 {
     SetInputState(new InputEventArgs()
     {
         Type = InputEventType.KeyDown, Key = key
     });
 }
示例#13
0
        public static void _OnSpecial(int key, int x, int y)
        {
            Window w = null;

            if (mvarLastFullscreenWindow != null)
            {
                w = mvarLastFullscreenWindow;
            }
            else
            {
                int handle = Internal.FreeGLUT.Methods.glutGetWindow();
                w = handleWindows[handle];
            }

            int modifiers = Internal.FreeGLUT.Methods.glutGetModifiers();

            KeyboardKey         keys         = GetSpecialKeyboardKey(key);
            KeyboardModifierKey modifierKeys = (KeyboardModifierKey)modifiers;

            KeyboardEventArgs e = new KeyboardEventArgs(keys, modifierKeys);

            w.OnKeyDown(e);

            foreach (Control ctl in w.Controls)
            {
                ctl.OnKeyDown(e);
            }
        }
示例#14
0
 protected override void OnKeyboardEvent(KeyboardKey key, bool pressed)
 {
     if (key == KeyboardKey.P && pressed)
     {
         _screenshot = true;
     }
 }
示例#15
0
 protected override void OnKeyboardEvent(KeyboardKey key, bool pressed)
 {
     if (key == KeyboardKey.Space && pressed)
     {
         ((D3D12GraphicsDevice)_graphicsDevice).UseRenderPass = !((D3D12GraphicsDevice)_graphicsDevice).UseRenderPass;
     }
 }
示例#16
0
 public void KeyDown(KeyboardKey key)
 {
     if (!keysdown.Contains(key))
     {
         keysdown.Add(key);
     }
 }
示例#17
0
        private void KeyHandler(KeyboardAction action, KeyboardKey key)
        {
            if (action == KeyboardAction.KeyRelease)
            {
                switch (key)
                {
                case KeyboardKey.Num_1:
                    window.SetClearColor(128, 52, 43);
                    break;

                case KeyboardKey.Num_2:
                    window.SetClearColor(28, 108, 218);
                    break;

                case KeyboardKey.T:
                    AddTimedEvent();
                    break;

                case KeyboardKey.Y:
                    AddTimedEvent((uint)random.Next());
                    break;

                case KeyboardKey.Escape:
                    window.CloseWindow();
                    break;
                }
            }
        }
示例#18
0
        public static bool IsAcceptableInput(this KeyboardKey key, AcceptableKeyboardKeyFlags flags = AcceptableKeyboardKeyFlags.AllNonFunctional)
        {
            bool output = false;

            if (flags.HasFlag(AcceptableKeyboardKeyFlags.Functional))
            {
                output = output ||
                         key == KeyboardKey.Backspace ||
                         key == KeyboardKey.Return;
            }

            if (flags.HasFlag(AcceptableKeyboardKeyFlags.Punctuation))
            {
                output = output ||
                         key == KeyboardKey.Space ||
                         key == KeyboardKey.Dash ||
                         key == KeyboardKey.Apostrophe;
            }

            if (flags.HasFlag(AcceptableKeyboardKeyFlags.Alphabetical))
            {
                output = output ||
                         (key >= KeyboardKey.A && key <= KeyboardKey.Z);
            }

            return(output);
        }
示例#19
0
        public void ApplyOnKeyUp(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed)
        {
            var  c            = KeyboardTables.KeyToChar(thisKeyPress, isShifted);
            bool thisKeyValid = (c != '\0' && !altPressed && !ctlPressed && !logoPressed);

            if (!thisKeyValid)
            {
                // If this isn't valid, reset the previously memorised key.
                _LastChar = '\0';
                return;
            }

            // If this keypress corresponds to a typable character and no modifier keys are pressed and the last character is valid: transpose them.
            if (_LastChar != '\0')
            {
                // Delete the two characters.
                output.KeyPress(KeyboardKey.BackSpace);
                output.KeyPress(KeyboardKey.BackSpace);

                // Echo them in reverse order.
                output.KeyPressWithModifier(KeyboardTables.CharToKeyStroke(c));
                output.KeyPressWithModifier(KeyboardTables.CharToKeyStroke(_LastChar));

                // That's the end of this fiddle.
                _IsComplete = true;
                return;
            }

            // Memorise the key for next call.
            _LastChar = c;
        }
示例#20
0
 public MouseEventArgs(int x, int y, MouseButton pressedButton, KeyboardKey keyModificators)
 {
     PressedButton   = pressedButton;
     KeyModificators = keyModificators;
     X = x;
     Y = y;
 }
示例#21
0
        public static void SendPasteKey()
        {
            var shiftKey = new KeyboardKey(Keys.ShiftKey);
            var altKey   = new KeyboardKey(Keys.Alt);
            var ctrlKey  = new KeyboardKey(Keys.ControlKey);
            var vKey     = new KeyboardKey(Keys.V);

            // Before injecting a paste command, first make sure that no modifiers are already
            // being pressed (which will throw off the Ctrl+v).
            // Since key state is notoriously unreliable, set a max sleep so that we don't get stuck
            var maxSleep = 250;

            // minimum sleep time
            Thread.Sleep(150);

            while (maxSleep > 0 && (shiftKey.State != 0 || altKey.State != 0 || ctrlKey.State != 0))
            {
                Thread.Sleep(maxSleep);
                maxSleep -= 50;
            }

            // Press keys in sequence. Don't use PressAndRelease since that seems to be too fast for most applications and the sequence gets lost.
            ctrlKey.Press();
            vKey.Press();
            Thread.Sleep(25);
            vKey.Release();
            Thread.Sleep(25);
            ctrlKey.Release();
        }
示例#22
0
    void OnGUI()
    {
        Event e = Event.current;

        if (!e.isKey)
        {
            return;
        }

        KeyCode     keyCode  = e.keyCode;
        KeyboardKey?maybeKey = keyCode.ToKeyboardKey();

        // filter out events with valid character but invalid keyCode (https://docs.unity3d.com/ScriptReference/EventType.KeyDown.html). also filter out non-input keys
        if (e.keyCode == KeyCode.None || maybeKey == null)
        {
            return;
        }

        KeyboardKey key = (KeyboardKey)maybeKey;

        UIKeyboard.Keys[key].SetActiveState(e.type == EventType.KeyDown);

        if (!acceptingInput || e.type != EventType.KeyDown)
        {
            return;
        }

        // TODO: key state feedback, hook up to agent.OnKeyPressed
        agent.PressKey(key, e.shift);
    }
示例#23
0
        private void KeyHandler(KeyboardAction action, KeyboardKey key)
        {
            //Console.WriteLine($"TestKeyEvents.KeyHandler({action}, {key})");
            if (action == KeyboardAction.KeyRelease)
            {
                switch (key)
                {
                case KeyboardKey.Num_1:
                    window.SetClearColor(128, 52, 43);
                    break;

                case KeyboardKey.Num_2:
                    window.SetClearColor(28, 108, 218);
                    break;

                case KeyboardKey.F1:
                    f1Pressed = true;
                    break;

                case KeyboardKey.Escape:
                    window.CloseWindow();
                    break;
                }
            }
        }
        public void KeyboardKeyPressed(int playerNo, KeyboardKey key, bool down)
        {
            switch (key)
            {
            case KeyboardKey.Z:      // left fire mapped to 2600 fire
                _inputState.RaiseInput(_jackNo, MachineInput.Fire, down);
                break;

            case KeyboardKey.X:      // right fire mapped to booster trigger
                _inputState.RaiseInput(_jackNo, MachineInput.Fire2, down);
                break;

            case KeyboardKey.Left:
                _inputState.RaiseInput(_jackNo, MachineInput.Left, down);
                break;

            case KeyboardKey.Right:
                _inputState.RaiseInput(_jackNo, MachineInput.Right, down);
                break;

            case KeyboardKey.Up:
                _inputState.RaiseInput(_jackNo, MachineInput.Up, down);
                break;

            case KeyboardKey.Down:
                _inputState.RaiseInput(_jackNo, MachineInput.Down, down);
                break;
            }
        }
示例#25
0
        /// <summary>
        /// Just use normal routine
        /// </summary>
        /// <param name="key"></param>
        public override void PerformKeyReleaseAlt(uint key)
        {
            //Console.WriteLine("PerformKeyReleaseAlt {0}", key);
            eventLock.EnterWriteLock();

            if (key < MODIFIER_MASK)
            {
                KeyboardKey temp = (KeyboardKey)key;
                if (pressedKeys.Contains(temp))
                {
                    keyReport.KeyUp(temp);
                    pressedKeys.Remove(temp);
                    syncKeyboard = true;
                }
            }
            else if (key < MODIFIER_ENHANCED)
            {
                KeyboardModifier modifier = (KeyboardModifier)(key & ~MODIFIER_MASK);
                if (modifiers.Contains(modifier))
                {
                    keyReport.KeyUp(modifier);
                    modifiers.Remove(modifier);
                    syncKeyboard = true;
                }
            }
            else
            {
                EnhancedKey temp = (EnhancedKey)(key & ~MODIFIER_ENHANCED);
                mediaKeyReport.KeyUp(temp);
                syncEnhancedKeyboard = true;
            }

            eventLock.ExitWriteLock();
        }
示例#26
0
        private static void KeyHandler(KeyboardAction action, KeyboardKey key)
        {
            //Console.WriteLine($"TestKeyEvents.KeyHandler({action}, {key})");
            if (action == KeyboardAction.KeyRelease)
            {
                switch (key)
                {
                case KeyboardKey.Num_1:
                    window.SetClearColor(128, 52, 43);
                    break;

                case KeyboardKey.Num_2:
                    window.SetClearColor(28, 108, 218);
                    break;

                case KeyboardKey.I:
                    var n = ran.Next();
                    test.Add(n, $"insert({n})");
                    break;

                case KeyboardKey.Escape:
                    window.CloseWindow();
                    break;
                }
            }
        }
示例#27
0
 public void KeyPress(KeyboardKey key = new KeyboardKey(), KeyboardModifier modikey = new KeyboardModifier(), int Intervals1 = 20, int Intervals2 = 20)
 {
     KeyDown(key, modikey);
     System.Threading.Thread.Sleep(Intervals1);
     KeyUp(key, modikey);
     System.Threading.Thread.Sleep(Intervals2);
 }
示例#28
0
        public Control_ColorizedKeycapBlank(KeyboardKey key, string image_path)
        {
            InitializeComponent();

            associatedKey = key.tag;

            this.Width  = key.width;
            this.Height = key.height;

            //Keycap adjustments
            if (string.IsNullOrWhiteSpace(key.image))
            {
                keyBorder.BorderThickness = new Thickness(1.5);
            }
            else
            {
                keyBorder.BorderThickness = new Thickness(0.0);
            }
            keyBorder.IsEnabled = key.enabled;

            if (!key.enabled)
            {
                ToolTipService.SetShowOnDisabled(keyBorder, true);
                keyBorder.ToolTip = new ToolTip {
                    Content = "Changes to this key are not supported"
                };
            }

            if (string.IsNullOrWhiteSpace(key.image))
            {
                keyCap.Text     = key.visualName;
                keyCap.Tag      = key.tag;
                keyCap.FontSize = key.font_size;
            }
            else
            {
                keyCap.Visibility = System.Windows.Visibility.Hidden;

                if (System.IO.File.Exists(image_path))
                {
                    var         memStream = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(image_path));
                    BitmapImage image     = new BitmapImage();
                    image.BeginInit();
                    image.StreamSource = memStream;
                    image.EndInit();

                    if (key.tag == DeviceKeys.NONE)
                    {
                        keyBorder.Background = new ImageBrush(image);
                    }
                    else
                    {
                        keyBorder.Background  = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 0, 0, 0));
                        keyBorder.OpacityMask = new ImageBrush(image);
                    }

                    isImage = true;
                }
            }
        }
示例#29
0
 /// <summary>
 /// Adds a new keyboard mapping for the same key with and without the shift key.
 /// </summary>
 /// <param name="scancode">The scancode received from the keyboard (without the shift key).</param>
 /// <param name="character">The character to represent the scancode or \0.</param>
 /// <param name="key">The keyboard key to respresent the scancode.</param>
 protected void AddKeyWithAndWithoutShift(uint scancode, char character, KeyboardKey key)
 {
     //Add normal key
     AddKey(scancode, character, key);
     //Add scancode for key with shift-key pressed
     AddKey(scancode << 16, character, key);
 }
示例#30
0
        public override void KeyboardKeyPressed(KeyboardKey key, bool down)
        {
            base.KeyboardKeyPressed(key, down);
            if (!down)
            {
                return;
            }
            switch (key)
            {
            case KeyboardKey.Down:
                _textcontrolAbout.ScrollDownByIncrement(1);
                break;

            case KeyboardKey.PageDown:
                _textcontrolAbout.ScrollDownByIncrement(10);
                break;

            case KeyboardKey.Up:
                _textcontrolAbout.ScrollUpByIncrement(1);
                break;

            case KeyboardKey.PageUp:
                _textcontrolAbout.ScrollUpByIncrement(10);
                break;

            case KeyboardKey.Escape:
                PopPage();
                break;
            }
        }
示例#31
0
 protected virtual void OnKeyUp(KeyboardKey key)
 {
     EventHandler<KeyboardKeyEventArgs> handler = KeyUp;
     if (handler != null)
     {
         handler(this, new KeyboardKeyEventArgs(KeyboardKeyEvent.Up, key));
     }
 }
示例#32
0
    public void AddInput(KeyboardKey key, bool uppercase, float time)
    {
        var next = new MomentaryInput {
            Key = key, Uppercase = uppercase, Time = time
        };

        Inputs.Add(next);
    }
示例#33
0
文件: Keyboard.cs 项目: Hathor86/oskd
        public override void Initialize()
        {
            foreach (Keys key in KeyboardLayoutReader.GetAllKeys())
            {
                KeyboardKey k = new KeyboardKey(Game, key);
                _Keys.Add(k);
            }

            base.Initialize();

            Scale = new Vector2(1.5f,1.5f);
        }
        public void SendKey(string key, KeyboardKey type)
        {
            try
            {
                switch (type)
                {
                    case KeyboardKey.KEY_TEXT:
                        Send(key);
                        break;
                    case KeyboardKey.KEY_ENTER:
                        SendKeys.SendWait(LdpKeys.ENTER);
                        break;
                    case KeyboardKey.KEY_DEL:
                        SendKeys.SendWait(LdpKeys.BACKSPACE);
                        break;
                }

            }
            catch
            {
                LdpLog.Error("SendKeys unhandled key: " + key);
            }
        }
示例#35
0
 /// <summary>
 /// Adds a new keyboard mapping for a key which has no character representation.
 /// Adds entries for the key with and without the shift key modifier.
 /// </summary>
 /// <param name="scancode">The scancode received from the keyboard (without the shift key).</param>
 /// <param name="key">The keyboard key to respresent the scancode.</param>
 protected void AddKeyWithShift(uint scancode, KeyboardKey key)
 {
     AddKeyWithAndWithoutShift(scancode, '\0', key);
 }
示例#36
0
 /// <summary>
 /// Adds a new keyboard mapping for a key which has no character representation.
 /// </summary>
 /// <param name="scancode">The scancode received from the keyboard.</param>
 /// <param name="key">The keyboard key to respresent the scancode.</param>
 protected void AddKey(uint scancode, KeyboardKey key)
 {
     AddKey(scancode, '\0', key);
 }
示例#37
0
 /// <summary>
 /// Adds a new keyboard mapping for the same key with and without the shift key.
 /// </summary>
 /// <param name="scancode">The scancode received from the keyboard (without the shift key).</param>
 /// <param name="character">The character to represent the scancode or \0.</param>
 /// <param name="key">The keyboard key to respresent the scancode.</param>
 protected void AddKeyWithAndWithoutShift(uint scancode, char character, KeyboardKey key)
 {
     //Add normal key
     AddKey(scancode, character, key);
     //Add scancode for key with shift-key pressed
     AddKey(scancode << 16, character, key);
 }
示例#38
0
 /// <summary>
 /// Adds a new keyboard mapping.
 /// </summary>
 /// <param name="scancode">The scancode received from the keyboard.</param>
 /// <param name="character">The character to represent the scancode or \0.</param>
 /// <param name="key">The keyboard key to respresent the scancode.</param>
 protected void AddKey(uint scancode, char character, KeyboardKey key)
 {
     KeyMappings.Add(new KeyMapping(scancode, character, key));
 }
示例#39
0
        private static void SetKey(KeyboardKey key, bool down)
        {
            if (is_down[(ushort)key] == down)
                return;

            is_down[(ushort)key] = down;

            User32.INPUT[] input_data = new User32.INPUT[1];
            input_data[0] = new User32.INPUT();

            input_data[0].type = (int)User32.InputType.INPUT_KEYBOARD;

            input_data[0].ki.dwFlags = 0;
            if ((int)key > 0x8000)
            {
                input_data[0].ki.wVk = (ushort)(key - 0x8000);
                // input_data[0].ki.dwFlags |= (uint)User32.SendInputFlags.KEYEVENTF_EXTENDEDKEY;
            }
            else
            {
                input_data[0].ki.wScan = (ushort)key;
                input_data[0].ki.dwFlags |= (uint)User32.SendInputFlags.KEYEVENTF_SCANCODE;
            }

            if (!down)
                input_data[0].ki.dwFlags |= (uint)User32.SendInputFlags.KEYEVENTF_KEYUP;

            uint result = User32.SendInput(1, input_data, Marshal.SizeOf(input_data[0]));

            if (result != 1)
                Console.WriteLine("SendInput result != 1 {=" + result + "}");
        }
示例#40
0
 public Shortcut(KeyboardKey key, KeyboardModifierKey modifierKeys)
 {
     mvarKey = key;
     mvarModifierKeys = modifierKeys;
 }
示例#41
0
 protected void SetUp()
 {
     keyboard = new FakeKeyboard();
     keyA = new KeyboardKey(keyboard, KeyboardKeyLabel.A);
     keyLeftControl = new KeyboardKey(keyboard, KeyboardKeyLabel.LeftControl);
 }
示例#42
0
 private int LowLevelKeyboardHook_Callback(int code, IntPtr wParam, IntPtr lParam, ref bool callNext)
 {
     if (code == HC_ACTION)
     {
         KBDLLHOOKSTRUCT llh = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
         bool handled = false;
         int msg = (int)wParam;
         if (KeyIntercepted != null)
         {
             KeyIntercepted(msg, llh.vkCode, llh.scanCode, llh.flags, llh.time, llh.dwExtraInfo, ref handled);
         }
         if (MessageIntercepted != null)
         {
             MessageIntercepted(new LowLevelKeyboardMessage((int)wParam, llh.vkCode, llh.scanCode, llh.flags, llh.time, llh.dwExtraInfo), ref handled);
         }
         if (handled)
         {
             callNext = false;
             return 1;
         }
         if (CharIntercepted != null && (msg == 256 || msg == 260))
         {
             // Note that dead keys are somehow tricky, since ToUnicode changes their state
             // in the keyboard driver. So, if we catch a dead key and call ToUnicode on it,
             // we will have to stop the hook; otherwise the deadkey appears twice on the screen.
             // On the other hand, we try to avoid calling ToUnicode on the key pressed after
             // the dead key (the one which is modified by the deadkey), because that would
             // drop the deadkey altogether. Resynthesizing the deadkey event is hard since
             // some deadkeys are unshifted but used on shifted characters or vice versa.
             // This solution will not lose any dead keys; its only drawback is that dead
             // keys are not properly translated. Better implementations are welcome.
             if (llh.vkCode == (int)Keys.ShiftKey ||
                 llh.vkCode == (int)Keys.LShiftKey ||
                 llh.vkCode == (int)Keys.RShiftKey ||
                 llh.vkCode == (int)Keys.LControlKey ||
                 llh.vkCode == (int)Keys.RControlKey ||
                 llh.vkCode == (int)Keys.ControlKey ||
                 llh.vkCode == (int)Keys.Menu ||
                 llh.vkCode == (int)Keys.LMenu ||
                 llh.vkCode == (int)Keys.RMenu)
             {
                 // ignore shift keys, they do not get modified by dead keys.
             }
             else if (currentDeadChar != '\0')
             {
                 CharIntercepted(msg, "" + (llh.vkCode == (int)Keys.Space ? currentDeadChar : '\x01'), true,
                     llh.vkCode, llh.scanCode, llh.flags, llh.time, llh.dwExtraInfo);
                 currentDeadChar = '\0';
             }
             else
             {
                 short dummy = new KeyboardKey(Keys.Capital).State; // will refresh CAPS LOCK state for current thread
                 byte[] kbdState = new byte[256];
                 ApiHelper.FailIfZero(GetKeyboardState(kbdState));
                 StringBuilder buff = new StringBuilder(64);
                 int length = ToUnicode((int)llh.vkCode, llh.scanCode, kbdState, buff, 64, 0);
                 if (length == -1)
                 {
                     currentDeadChar = buff[0];
                     callNext = false;
                     return 1;
                 }
                 if (buff.Length != length)
                     buff.Remove(length, buff.Length - length);
                 CharIntercepted(msg, buff.ToString(), false,
                     llh.vkCode, llh.scanCode, llh.flags, llh.time, llh.dwExtraInfo);
             }
         }
     }
     return 0;
 }
示例#43
0
 public static bool IsKeyboardKeyUpRightNow( KeyboardKey key )
 {
     return CurrentKeyboardState.IsKeyUp ( key ) &&
         LastKeyboardState.IsKeyDown ( key );
 }
 public KeyboardKeyEventArgs(KeyboardKeyEvent keyboardEvent, KeyboardKey key)
 {
     _keyboardEvent = keyboardEvent;
     _key = key;
 }
示例#45
0
 private void HandleKey(KeyboardKey key, Action<double> action)
 {
     long startTime;
     if (m_keyDownTime.TryGetValue(key, out startTime))
     {
         long now = Stopwatch.GetTimestamp();
         long moveTime = now - startTime;
         action((double)moveTime / Stopwatch.Frequency);
         m_keyDownTime[key] = now;
     }
 }
示例#46
0
 public static void PressKey(KeyboardKey key)
 {
     SetKey(key, true);
     Thread.Sleep(50);
     SetKey(key, false);
 }
示例#47
0
        /// <summary>
        /// Gets the first KeyboardKey which represents the specified scancode.
        /// </summary>
        /// <param name="aScanCode">The scancode to get the character for.</param>
        /// <param name="aValue">
        /// Output. The KeyboardKey which represents the scancode or KeyboardKey.NoName if none found.
        /// </param>
        /// <returns>True if a KeyboardKey to represent the scancode was found. Otherwise false.</returns>
        public bool GetKeyValue(uint aScanCode, out KeyboardKey aValue)
        {
            //Loops through all the key mappings to find the one which matches
            //  the specified scancode. Output value goes in aValue, return true
            //  indicates key mapping was found. Return false indicates key 
            //  mapping was not found.

            for (int i = 0; i < KeyMappings.Count; i++)
            {
                if (((KeyMapping)KeyMappings[i]).Scancode == aScanCode)
                {
                    aValue = ((KeyMapping)KeyMappings[i]).Key;
                    return true;
                }
            }

            aValue = KeyboardKey.NoName;
            return false;
        }
示例#48
0
 /// <summary>
 /// Initialises a new key mapping.
 /// </summary>
 /// <param name="aScanCode">The scancode to map.</param>
 /// <param name="aValue">The character to represent the scancode.</param>
 /// <param name="aKey">The character to represent the scancode.</param>
 public KeyMapping(uint aScanCode, char aValue, KeyboardKey aKey)
 {
     Scancode = aScanCode;
     Value = aValue;
     Key = aKey;
 }
示例#49
0
        /// <summary>
        /// Non-blocking. Gets the oldest key pressed (which may be NoName) or NoName if none queued.
        /// </summary>
        /// <param name="c">The dequeued key or NoName.</param>
        /// <returns>True if a key was dequeued. Otherwise false.</returns>
        public bool GetKey(out KeyboardKey c)
        {
            //Same idea as GetChar - see that for docs.

            if (scancodeBuffer.Count > 0)
            {
                GetKeyValue(Dequeue(), out c);
                return true;
            }
            else
            {
                c = KeyboardKey.NoName;

                return false;
            }
        }
示例#50
0
 public static void KeyDown(KeyboardKey key)
 {
     SetKey(key, true);
 }
示例#51
0
 /// <summary>
 /// Initialises a new key mapping without a character representation.
 /// </summary>
 /// <param name="aScanCode">The scancode to map.</param>
 /// <param name="aKey">The character to represent the scancode.</param>
 public KeyMapping(uint aScanCode, KeyboardKey aKey)
 {
     Scancode = aScanCode;
     Value = '\0';
     Key = aKey;
 }
示例#52
0
 public void keyUp(KeyboardKey key)
 {
     pressedKeys.Remove(key);
 }
示例#53
0
 public static bool IsDown(KeyboardKey key)
 {
     return is_down[(ushort)key];
 }
示例#54
0
 public static void KeyUp(KeyboardKey key)
 {
     SetKey(key, false);
 }
示例#55
0
 public KeyboardEventArgs(KeyboardKey keys, KeyboardModifierKey modifierKeys)
 {
     mvarKeys = keys;
     mvarModifierKeys = modifierKeys;
 }
 private uint GetAccelKeyForKeyboardKey(KeyboardKey key)
 {
     switch (key) {
         case KeyboardKey.A: return (uint)'A';
         case KeyboardKey.B: return (uint)'B';
         case KeyboardKey.C: return (uint)'C';
         case KeyboardKey.D: return (uint)'D';
         case KeyboardKey.E: return (uint)'E';
         case KeyboardKey.F: return (uint)'F';
         case KeyboardKey.G: return (uint)'G';
         case KeyboardKey.H: return (uint)'H';
         case KeyboardKey.I: return (uint)'I';
         case KeyboardKey.J: return (uint)'J';
         case KeyboardKey.K: return (uint)'K';
         case KeyboardKey.L: return (uint)'L';
         case KeyboardKey.M: return (uint)'M';
         case KeyboardKey.N: return (uint)'N';
         case KeyboardKey.O: return (uint)'O';
         case KeyboardKey.P: return (uint)'P';
         case KeyboardKey.Q: return (uint)'Q';
         case KeyboardKey.R: return (uint)'R';
         case KeyboardKey.S: return (uint)'S';
         case KeyboardKey.T: return (uint)'T';
         case KeyboardKey.U: return (uint)'U';
         case KeyboardKey.V: return (uint)'V';
         case KeyboardKey.W: return (uint)'W';
         case KeyboardKey.X: return (uint)'X';
         case KeyboardKey.Y: return (uint)'Y';
         case KeyboardKey.Z: return (uint)'Z';
     }
     return 0;
 }
示例#57
0
 //Press the specified modifier and key.
 public void SendKey(KeyboardModifier modifier, KeyboardKey key)
 {
     SendKey(modifier, key, true);
 }
示例#58
0
 public void keyDown(KeyboardKey key)
 {
     pressedKeys.Add(key);
 }
示例#59
0
 public bool IsKeyUp( KeyboardKey key )
 {
     if ( PressedKeys == null )
         return false;
     return !PressedKeys.Contains ( key );
 }
示例#60
0
        //Press the specified modifier and key, and optionally leave them held down.
        public void SendKey(KeyboardModifier modifier, KeyboardKey key, bool sendClear)
        {
            var data = new byte[8];
              data[0] = (byte)modifier;
              data[2] = (byte)key;
              _SendKeypressData(data);

              if (sendClear)
            ClearKeypresses();
        }