private void SendKeyMap(PadToKeyInput input, InputKeyInfo oldState, InputKeyInfo 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); } } }
private void SendInput(InputKeyInfo newState, InputKeyInfo 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) { 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); } }