Esempio n. 1
0
 /// <summary>
 /// If your form needs this kind of input focus, be sure to say so.
 /// Really, this only makes sense for mouse, but I've started building it out for other things
 /// Why is this receiving a control, but actually using it as a Form (where the WantingMouseFocus is checked?)
 /// Because later we might change it to work off the control, specifically, if a control is supplied (normally actually a Form will be supplied)
 /// </summary>
 public void ControlInputFocus(Control c, ClientInputFocus types, bool wants)
 {
     if (types.HasFlag(ClientInputFocus.Mouse) && wants)
     {
         _wantingMouseFocus.Add(c);
     }
     if (types.HasFlag(ClientInputFocus.Mouse) && !wants)
     {
         _wantingMouseFocus.Remove(c);
     }
 }
Esempio n. 2
0
        private void HandleButton(string button, bool newState, ClientInputFocus source)
        {
            var currentModifier = button switch
            {
//				"LeftWin" => ModifierKey.Win,
//				"RightWin" => ModifierKey.Win,
                "LeftShift" => ModifierKey.Shift,
                "RightShift" => ModifierKey.Shift,
                "LeftCtrl" => ModifierKey.Control,
                "RightCtrl" => ModifierKey.Control,
                "LeftAlt" => ModifierKey.Alt,
                "RightAlt" => ModifierKey.Alt,
                _ => ModifierKey.None
            };

            if (EnableIgnoreModifiers && currentModifier != ModifierKey.None)
            {
                return;
            }
            if (_lastState[button] == newState)
            {
                return;
            }

            // apply
            // NOTE: this is not quite right. if someone held leftshift+rightshift it would be broken. seems unlikely, though.
            if (currentModifier != ModifierKey.None)
            {
                if (newState)
                {
                    _modifiers |= currentModifier;
                }
                else
                {
                    _modifiers &= ~currentModifier;
                }
            }

            // don't generate events for things like Ctrl+LeftControl
            ModifierKey mods = _modifiers;

            if (currentModifier != ModifierKey.None)
            {
                mods &= ~currentModifier;
            }

            var ie = new InputEvent
            {
                EventType     = newState ? InputEventType.Press : InputEventType.Release,
                LogicalButton = new LogicalButton(button, mods),
                Source        = source
            };

            _lastState[button] = newState;

            // track the pressed events with modifiers that we send so that we can send corresponding unpresses with modifiers
            // this is an interesting idea, which we may need later, but not yet.
            // for example, you may see this series of events: press:ctrl+c, release:ctrl, release:c
            // but you might would rather have press:ctrl+c, release:ctrl+c
            // this code relates the releases to the original presses.
            // UPDATE - this is necessary for the frame advance key, which has a special meaning when it gets stuck down
            // so, i am adding it as of 11-sep-2011
            if (newState)
            {
                _modifierState[button] = ie.LogicalButton;
            }
            else
            {
                if (_modifierState.TryGetValue(button, out var buttonModifierState))
                {
                    if (buttonModifierState != ie.LogicalButton && !_ignoreEventsNextPoll)
                    {
                        _newEvents.Add(
                            new InputEvent
                        {
                            LogicalButton = buttonModifierState,
                            EventType     = InputEventType.Release,
                            Source        = source
                        });
                    }
                    _modifierState.Remove(button);
                }
            }

            if (!_ignoreEventsNextPoll)
            {
                _newEvents.Add(ie);
            }
        }
Esempio n. 3
0
        private void HandleButton(string button, bool newState, ClientInputFocus source)
        {
            if (!(_currentConfig.MergeLAndRModifierKeys && _modifierKeyPreMap.TryGetValue(button, out var button1)))
            {
                button1 = button;
            }
            var modIndex        = _currentConfig.ModifierKeysEffective.IndexOf(button1);
            var currentModifier = modIndex is - 1 ? 0U : 1U << modIndex;

            if (EnableIgnoreModifiers && currentModifier is not 0U)
            {
                return;
            }
            if (newState == _lastState[button1])
            {
                return;
            }

            if (currentModifier is not 0U)
            {
                if (newState)
                {
                    _modifiers |= currentModifier;
                }
                else
                {
                    _modifiers &= ~currentModifier;
                }
            }

            // don't generate events for things like Ctrl+LeftControl
            var mods = _modifiers;

            if (currentModifier is not 0U)
            {
                mods &= ~currentModifier;
            }

            var ie = new InputEvent
            {
                EventType     = newState ? InputEventType.Press : InputEventType.Release,
                LogicalButton = new(button1, mods, () => _getConfigCallback().ModifierKeysEffective),
                Source        = source
            };

            _lastState[button1] = newState;

            // track the pressed events with modifiers that we send so that we can send corresponding unpresses with modifiers
            // this is an interesting idea, which we may need later, but not yet.
            // for example, you may see this series of events: press:ctrl+c, release:ctrl, release:c
            // but you might would rather have press:ctrl+c, release:ctrl+c
            // this code relates the releases to the original presses.
            // UPDATE - this is necessary for the frame advance key, which has a special meaning when it gets stuck down
            // so, i am adding it as of 11-sep-2011
            if (newState)
            {
                _modifierState[button1] = ie.LogicalButton;
            }
            else
            {
                if (_modifierState.TryGetValue(button1, out var buttonModifierState))
                {
                    if (buttonModifierState != ie.LogicalButton && !_ignoreEventsNextPoll)
                    {
                        _newEvents.Add(
                            new InputEvent
                        {
                            LogicalButton = buttonModifierState,
                            EventType     = InputEventType.Release,
                            Source        = source
                        });
                    }
                    _modifierState.Remove(button1);
                }
            }

            if (!_ignoreEventsNextPoll)
            {
                _newEvents.Add(ie);
            }
        }