コード例 #1
0
        public override bool Equals(object obj)
        {
            JoyInputState c1 = this;
            JoyInputState c2 = obj as JoyInputState;

            if (c2 == null)
            {
                return(false);
            }

            if (c1._keys.Count != c2._keys.Count)
            {
                return(false);
            }

            foreach (var key in c1._keys)
            {
                InputValue value;
                if (!c2._keys.TryGetValue(key.Key, out value))
                {
                    return(false);
                }

                if (value.Value != key.Value.Value || value.IsAxis != key.Value.IsAxis)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public JoyInputState Clone()
        {
            JoyInputState clone = new JoyInputState();

            clone._keys = new Dictionary <int, InputValue>(_keys);
            return(clone);
        }
コード例 #3
0
        public Joystick(int id, IntPtr joystick, Controller conf)
        {
            Id          = id;
            SdlJoystick = joystick;
            Controller  = conf;

            State    = new JoyInputState();
            OldState = new JoyInputState();
        }
コード例 #4
0
        private void ProcessJoystickState(int playerIndex, JoyInputState keyState, JoyInputState prevState)
        {
            //Debug.WriteLine("ProcessJoystickState : " + keyState.ToString() + " - OldState : " + prevState.ToString());

            IntPtr hWndProcess;
            bool   isDesktop;
            string process = GetActiveProcessFileName(out isDesktop, out hWndProcess);

            var mapping = _mapping[process];

            if (mapping != null)
            {
                foreach (var keyMap in mapping.Input)
                {
                    if (!keyMap.IsValid())
                    {
                        continue;
                    }

                    if (keyMap.ControllerIndex >= 0 && keyMap.ControllerIndex != playerIndex)
                    {
                        continue;
                    }

                    SendInput(keyState, prevState, hWndProcess, process, keyMap);
                }
            }

            var commonMapping = _mapping["*"];

            if (commonMapping != null)
            {
                foreach (var keyMap in commonMapping.Input)
                {
                    if (!keyMap.IsValid())
                    {
                        continue;
                    }

                    if (keyMap.ControllerIndex >= 0 && keyMap.ControllerIndex != playerIndex)
                    {
                        continue;
                    }

                    if (mapping != null && mapping[keyMap.Name] != null)
                    {
                        continue;
                    }

                    SendInput(keyState, prevState, hWndProcess, process, keyMap);
                }
            }
        }
コード例 #5
0
        public static JoyInputState operator |(JoyInputState a, JoyInputState b)
        {
            JoyInputState ret = new JoyInputState();

            ret._keys = new Dictionary <int, InputValue>(a._keys);

            foreach (var kb in b._keys)
            {
                ret._keys[kb.Key] = kb.Value;
            }

            return(ret);
        }
コード例 #6
0
        private void SendKeyMap(PadToKeyInput input, JoyInputState oldState, JoyInputState newState, string processName)
        {
            if (oldState.HasNewInput(input.Name, newState))
            {
                if (processName == null)
                {
                    SimpleLogger.Instance.Info("SendKey : Release '" + input.Keys + "' to <unknown process>");
                }
                else
                {
                    SimpleLogger.Instance.Info("SendKey : Release '" + input.Keys + "' to " + processName);
                }

                if (input.ScanCodes.Length != 0)
                {
                    foreach (uint sc in input.ScanCodes)
                    {
                        SendKey.SendScanCode(sc, false);
                    }
                }
                else if (input.Keys != Keys.None)
                {
                    SendKey.Send(input.Keys, false);
                }
            }
            else if (newState.HasNewInput(input.Name, oldState))
            {
                if (processName == null)
                {
                    SimpleLogger.Instance.Info("SendKey : Press '" + input.Keys + "' to <unknown process>");
                }
                else
                {
                    SimpleLogger.Instance.Info("SendKey : Press '" + input.Keys + "' to " + processName);
                }

                if (input.ScanCodes.Length != 0)
                {
                    foreach (uint sc in input.ScanCodes)
                    {
                        SendKey.SendScanCode(sc, true);
                    }
                }
                else if (input.Keys != Keys.None)
                {
                    SendKey.Send(input.Keys, true);
                }
            }
        }
コード例 #7
0
        private void SendInput(JoyInputState newState, JoyInputState oldState, IntPtr hWndProcess, string process, PadToKeyInput input)
        {
            if (input.Type == PadToKeyType.Mouse && (input.Code == "CLICK" || input.Code == "RCLICK" || input.Code == "MCLICK"))
            {
                if (oldState.HasNewInput(input.Name, newState)) // Released
                {
                    if (input.Code == "CLICK")
                    {
                        SendKey.SendMouseInput(SendKey.MouseInput.Click, false);
                    }
                    else if (input.Code == "RCLICK")
                    {
                        SendKey.SendMouseInput(SendKey.MouseInput.RClick, false);
                    }
                    else if (input.Code == "MCLICK")
                    {
                        SendKey.SendMouseInput(SendKey.MouseInput.MClick, false);
                    }
                }
                else if (newState.HasNewInput(input.Name, oldState)) // Pressed
                {
                    if (input.Code == "CLICK")
                    {
                        SendKey.SendMouseInput(SendKey.MouseInput.Click, true);
                    }
                    else if (input.Code == "RCLICK")
                    {
                        SendKey.SendMouseInput(SendKey.MouseInput.RClick, true);
                    }
                    else if (input.Code == "MCLICK")
                    {
                        SendKey.SendMouseInput(SendKey.MouseInput.MClick, true);
                    }
                }

                return;
            }

            if (input.Type == PadToKeyType.Mouse && (input.Code == "X" || input.Code == "Y"))
            {
                if (!newState.HasFlag(input.Name) && !newState.HasFlag(RevertedAxis(input.Name)))
                {
                    // Debug.WriteLine("STOP MOUSE MOVE " + input.Code);

                    // Stop
                    if (input.Code == "X")
                    {
                        _mouseMove.X = 0;
                    }
                    else
                    {
                        _mouseMove.Y = 0;
                    }

                    if (_mouseMove.IsEmpty && _mouseTimer != null)
                    {
                        _mouseTimer.Dispose();
                        _mouseTimer = null;
                    }
                }
                else if (newState.HasNewInput(input.Name, oldState, true))
                {
                    // Moving
                    if (input.Code == "X")
                    {
                        _mouseMove.X = newState.GetMouseInputValue(input.Name);
                    }
                    else
                    {
                        _mouseMove.Y = newState.GetMouseInputValue(input.Name);
                    }

                    // Debug.WriteLine("Mouse @ " + _mouseMove.ToString());

                    if (_mouseMove.IsEmpty)
                    {
                        if (_mouseTimer != null)
                        {
                            _mouseTimer.Dispose();
                        }

                        _mouseTimer = null;
                    }
                    else if (_mouseTimer == null)
                    {
                        _mouseTimer = new System.Threading.Timer(new TimerCallback(OnMouseTimerProc), this, 0, 1);
                    }
                }
                else if (newState.HasNewInput(RevertedAxis(input.Name), oldState, true))
                {
                    // Moving
                    if (input.Code == "X")
                    {
                        _mouseMove.X = newState.GetMouseInputValue(RevertedAxis(input.Name));
                    }
                    else
                    {
                        _mouseMove.Y = newState.GetMouseInputValue(RevertedAxis(input.Name));
                    }

                    //  Debug.WriteLine("Mouse @ " + _mouseMove.ToString());

                    if (_mouseMove.IsEmpty)
                    {
                        if (_mouseTimer != null)
                        {
                            _mouseTimer.Dispose();
                        }

                        _mouseTimer = null;
                    }
                    else if (_mouseTimer == null)
                    {
                        _mouseTimer = new System.Threading.Timer(new TimerCallback(OnMouseTimerProc), this, 0, 5);
                    }
                }

                return;
            }

            if (input.Key != null && (input.Key.StartsWith("(") || input.Key.StartsWith("{")))
            {
                if (newState.HasNewInput(input.Name, oldState))
                {
                    if (input.Keys != 0)
                    {
                        if (process == null)
                        {
                            SimpleLogger.Instance.Info("SendKey : " + input.Key + " to <unknown process>");
                        }
                        else
                        {
                            SimpleLogger.Instance.Info("SendKey : " + input.Key + " to " + process);
                        }
                    }

                    if (input.Key == "(%{CLOSE})" && hWndProcess != IntPtr.Zero)
                    {
                        const int WM_CLOSE = 0x0010;
                        User32.SendMessage(hWndProcess, WM_CLOSE, 0, 0);
                    }
                    else if (input.Key == "(%{KILL})" && hWndProcess != IntPtr.Zero)
                    {
                        KillProcess(hWndProcess, process);
                    }
                    else if (input.Key == "(%{F4})" && process == "emulationstation")
                    {
                        SendKey.Send(Keys.Alt, true);
                        SendKey.Send(Keys.F4, true);
                        SendKey.Send(Keys.Alt, false);
                        SendKey.Send(Keys.F4, false);
                    }
                    else
                    {
                        SendKeys.SendWait(input.Key);
                    }
                }
            }
            else if (input.Keys != 0 || input.ScanCodes.Length != 0)
            {
                SendKeyMap(input, oldState, newState, process);
            }
        }
コード例 #8
0
        public bool HasNewInput(InputKey k, JoyInputState old, bool checkAxisChanged = false)
        {
            var newValues = FromInputKey(k);

            if (newValues.Count == 0)
            {
                return(false);
            }

            var oldValues = old.FromInputKey(k);

            if (oldValues.Count == 0)
            {
                if (newValues.Any(v => v.Value.IsAxis))
                {
                    foreach (var nv in newValues.Where(v => v.Value.IsAxis))
                    {
                        oldValues[nv.Key] = new InputValue(0, true);
                    }
                }
                else
                {
                    return(true);
                }
            }

            foreach (var ov in oldValues)
            {
                if (!newValues.ContainsKey(ov.Key))
                {
                    return(false);
                }

                var oldVal = oldValues[ov.Key];
                var newVal = newValues[ov.Key];

                if (oldVal.IsAxis)
                {
                    if (checkAxisChanged)
                    {
                        if (oldVal.Value != newVal.Value)
                        {
                            return(true);
                        }
                    }

                    const int DEADZONE = 20000;

                    bool oldOutOfDeadZone = Math.Abs(oldVal.Value) >= DEADZONE;
                    bool newOutOfDeadZone = Math.Abs(newVal.Value) >= DEADZONE;

                    if (newOutOfDeadZone && !oldOutOfDeadZone)
                    {
                        return(true);
                    }
                }
                else if (oldVal.Value != newVal.Value)
                {
                    return(true);
                }
            }

            return(false);
        }