From e4c0690306fc00f1659a77790a8cd2c04060c39e Mon Sep 17 00:00:00 2001 From: David Khachaturov Date: Tue, 7 Apr 2020 16:20:56 +0100 Subject: [PATCH] - Implemented active-gyro button --- BetterJoyForCemu/Joycon.cs | 18 ++++++++++++++---- BetterJoyForCemu/Program.cs | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/BetterJoyForCemu/Joycon.cs b/BetterJoyForCemu/Joycon.cs index e15be2f..65eb44f 100644 --- a/BetterJoyForCemu/Joycon.cs +++ b/BetterJoyForCemu/Joycon.cs @@ -42,6 +42,7 @@ namespace BetterJoyForCemu { public bool isSnes = false; bool isUSB = false; public Joycon other; + public bool active_gyro = false; public bool send = true; @@ -569,16 +570,25 @@ namespace BetterJoyForCemu { if (extraGyroFeature == "joy") { // TODO } else if (extraGyroFeature == "mouse" && (isPro || (other == null) || (other != null && (Boolean.Parse(ConfigurationManager.AppSettings["GyroMouseLeftHanded"]) ? isLeft : !isLeft)))) { + string res_val = Config.Value("active_gyro"); + if (res_val.StartsWith("joy_")) + if (buttons_down[Int32.Parse(res_val.Substring(4))]) + active_gyro = true; + else if (buttons_up[Int32.Parse(res_val.Substring(4))]) + active_gyro = false; + float dt = 0.015f; // 15ms // gyro data is in degrees/s - int dx = (int)(GyroMouseSensitivity * (gyr_g.Z * dt) * (Math.Abs(gyr_g.Z) < 1 ? 0 : 1)); - int dy = (int)-(GyroMouseSensitivity * (gyr_g.Y * dt) * (Math.Abs(gyr_g.Y) < 1 ? 0 : 1)); + if (Config.Value("active_gyro") == "0" || active_gyro) { + int dx = (int)(GyroMouseSensitivity * (gyr_g.Z * dt) * (Math.Abs(gyr_g.Z) < 1 ? 0 : 1)); + int dy = (int)-(GyroMouseSensitivity * (gyr_g.Y * dt) * (Math.Abs(gyr_g.Y) < 1 ? 0 : 1)); - WindowsInput.Simulate.Events().MoveBy(dx, dy).Invoke(); + WindowsInput.Simulate.Events().MoveBy(dx, dy).Invoke(); + } // reset mouse position to centre of primary monitor - string res_val = Config.Value("reset_mouse"); + res_val = Config.Value("reset_mouse"); if (res_val.StartsWith("joy_")) if (buttons_down[Int32.Parse(res_val.Substring(4))]) WindowsInput.Simulate.Events().MoveTo(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2).Invoke(); diff --git a/BetterJoyForCemu/Program.cs b/BetterJoyForCemu/Program.cs index 00b74c0..e5a0343 100644 --- a/BetterJoyForCemu/Program.cs +++ b/BetterJoyForCemu/Program.cs @@ -442,6 +442,20 @@ namespace BetterJoyForCemu { if (res_val.StartsWith("mse_")) if ((int)e.Data.ButtonDown.Button == Int32.Parse(res_val.Substring(4))) WindowsInput.Simulate.Events().MoveTo(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2).Invoke(); + + res_val = Config.Value("active_gyro"); + if (res_val.StartsWith("mse_")) + if ((int)e.Data.ButtonDown.Button == Int32.Parse(res_val.Substring(4))) + foreach (var i in mgr.j) + i.active_gyro = true; + } + + if (e.Data.ButtonUp != null) { + string res_val = Config.Value("active_gyro"); + if (res_val.StartsWith("mse_")) + if ((int)e.Data.ButtonUp.Button == Int32.Parse(res_val.Substring(4))) + foreach (var i in mgr.j) + i.active_gyro = false; } } @@ -451,6 +465,20 @@ namespace BetterJoyForCemu { if (res_val.StartsWith("key_")) if ((int)e.Data.KeyDown.Key == Int32.Parse(res_val.Substring(4))) WindowsInput.Simulate.Events().MoveTo(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2).Invoke(); + + res_val = Config.Value("active_gyro"); + if (res_val.StartsWith("key_")) + if ((int)e.Data.KeyDown.Key == Int32.Parse(res_val.Substring(4))) + foreach (var i in mgr.j) + i.active_gyro = true; + } + + if (e.Data.KeyUp != null) { + string res_val = Config.Value("active_gyro"); + if (res_val.StartsWith("key_")) + if ((int)e.Data.KeyUp.Key == Int32.Parse(res_val.Substring(4))) + foreach (var i in mgr.j) + i.active_gyro = false; } }