public void SendKeys(KeyData data) { foreach (var key in data.KeysDown) { PressKey(key, true); } foreach (var key in data.KeysUp) { PressKey(key, false); } }
public KeyData Translate(JoystickState input) { var keyData = new KeyData(); var restrictX = vm.FourWayInput && Math.Abs(AXIS_MAX / 2 - input.X) < Math.Abs(AXIS_MAX / 2 - input.Y); var restrictY = vm.FourWayInput && Math.Abs(AXIS_MAX / 2 - input.X) >= Math.Abs(AXIS_MAX / 2 - input.Y); // Press left key if (input.X < deadzoneXRange.Item1 && !restrictX && !state.Left) { state.Left = true; keyData.KeysDown.Add(vm.LeftInput); } // Release left key else if ((input.X >= deadzoneXRange.Item1 || restrictX) && state.Left) { state.Left = false; keyData.KeysUp.Add(vm.LeftInput); } // Press right key if (input.X > deadzoneXRange.Item2 && !restrictX && !state.Right) { state.Right = true; keyData.KeysDown.Add(vm.RightInput); } // Release right key else if ((input.X <= deadzoneXRange.Item2 || restrictX) && state.Right) { state.Right = false; keyData.KeysUp.Add(vm.RightInput); } // Press up key if (input.Y < deadzoneYRange.Item1 && !restrictY && !state.Up) { state.Up = true; keyData.KeysDown.Add(vm.UpInput); } // Release up key else if ((input.Y >= deadzoneYRange.Item1 || restrictY) && state.Up) { state.Up = false; keyData.KeysUp.Add(vm.UpInput); } // Press down key if (input.Y > deadzoneYRange.Item2 && !restrictY && !state.Down) { state.Down = true; keyData.KeysDown.Add(vm.DownInput); } // Release down key else if ((input.Y <= deadzoneYRange.Item2 || restrictY) && state.Down) { state.Down = false; keyData.KeysUp.Add(vm.DownInput); } oldInput = input; return(keyData); }