示例#1
0
        private void SendKeyMap(PadToKeyInput input, InputKey prevState, InputKey keyState, string processName)
        {
            if (prevState.HasFlag(input.Name) && !keyState.HasFlag(input.Name))
            {
                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.ScanCode != 0)
                {
                    SendKey.Send(input.ScanCode, false);
                }
                else
                {
                    SendKey.Send(input.Keys, false);
                }
            }
            else if (!prevState.HasFlag(input.Name) && keyState.HasFlag(input.Name))
            {
                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.ScanCode != 0)
                {
                    SendKey.Send(input.ScanCode, false);
                }
                else
                {
                    SendKey.Send(input.Keys, true);
                }
            }
        }
示例#2
0
        private void ProcessJoystickState(InputKey keyState, InputKey prevState)
        {
            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 (string.IsNullOrEmpty(keyMap.Key) && string.IsNullOrEmpty(keyMap.Code))
                    {
                        continue;
                    }

                    if (keyMap.Key != null && (keyMap.Key.StartsWith("(") || keyMap.Key.StartsWith("{")))
                    {
                        if (!prevState.HasFlag(keyMap.Name) && keyState.HasFlag(keyMap.Name))
                        {
                            if (keyMap.Keys != 0)
                            {
                                if (process == null)
                                {
                                    SimpleLogger.Instance.Info("SendKey : " + keyMap.Key + " to <unknown process>");
                                }
                                else
                                {
                                    SimpleLogger.Instance.Info("SendKey : " + keyMap.Key + " to " + process);
                                }
                            }

                            if (keyMap.Key == "(%{CLOSE})" && hWndProcess != IntPtr.Zero)
                            {
                                SendMessage(hWndProcess, WM_CLOSE, 0, 0);
                            }
                            else if (keyMap.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(keyMap.Key);
                            }
                        }
                    }
                    else if (keyMap.Keys != 0 || keyMap.ScanCode != 0)
                    {
                        SendKeyMap(keyMap, prevState, keyState, process);
                    }
                }
            }

            var commonMapping = _mapping["*"];

            if (commonMapping != null)
            {
                foreach (var keyMap in commonMapping.Input)
                {
                    if (string.IsNullOrEmpty(keyMap.Key) && string.IsNullOrEmpty(keyMap.Code))
                    {
                        continue;
                    }

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

                    if (keyMap.Key != null && (keyMap.Key.StartsWith("(") || keyMap.Key.StartsWith("{")))
                    {
                        if (!prevState.HasFlag(keyMap.Name) && keyState.HasFlag(keyMap.Name))
                        {
                            if (keyMap.Keys != 0)
                            {
                                if (process == null)
                                {
                                    SimpleLogger.Instance.Info("SendKey : " + keyMap.Key + " to <unknown process>");
                                }
                                else
                                {
                                    SimpleLogger.Instance.Info("SendKey : " + keyMap.Key + " to " + process);
                                }
                            }

                            if (keyMap.Key == "(%{CLOSE})" && hWndProcess != IntPtr.Zero)
                            {
                                SendMessage(hWndProcess, WM_CLOSE, 0, 0);
                            }
                            else if (keyMap.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(keyMap.Key);
                            }
                        }
                    }
                    else if (keyMap.Keys != 0 || keyMap.ScanCode != 0)
                    {
                        SendKeyMap(keyMap, prevState, keyState, process);
                    }
                }
            }
        }