diff --git a/BetterJoyForCemu/.nuget/mouse-keyboard-hook-logo.png b/BetterJoyForCemu/.nuget/mouse-keyboard-hook-logo.png new file mode 100644 index 0000000..a3c31cf Binary files /dev/null and b/BetterJoyForCemu/.nuget/mouse-keyboard-hook-logo.png differ diff --git a/BetterJoyForCemu/BetterJoyForCemu.csproj b/BetterJoyForCemu/BetterJoyForCemu.csproj index 3e4b36a..318e76c 100644 --- a/BetterJoyForCemu/BetterJoyForCemu.csproj +++ b/BetterJoyForCemu/BetterJoyForCemu.csproj @@ -143,6 +143,9 @@ + + ..\packages\WindowsInput.6.1.1\lib\net461\WindowsInput.dll + @@ -170,10 +173,13 @@ - + + Designer + + diff --git a/BetterJoyForCemu/Joycon.cs b/BetterJoyForCemu/Joycon.cs index bf458c5..b02ad7c 100644 --- a/BetterJoyForCemu/Joycon.cs +++ b/BetterJoyForCemu/Joycon.cs @@ -13,6 +13,7 @@ using Nefarius.ViGEm.Client.Targets; using Nefarius.ViGEm.Client.Targets.Xbox360; using System.Runtime.InteropServices; using System.Windows.Forms; +using WindowsInput; namespace BetterJoyForCemu { // For mouse movement @@ -364,7 +365,7 @@ namespace BetterJoyForCemu { HIDapi.hid_write(handle, a, new UIntPtr(2)); a[0] = 0x80; a[1] = 0x4; // Prevent HID timeout - HIDapi.hid_write(handle, a, new UIntPtr(2)); + HIDapi.hid_write(handle, a, new UIntPtr(2)); // doesn't actually prevent timout... dump_calibration_data(); } @@ -383,6 +384,10 @@ namespace BetterJoyForCemu { HIDapi.hid_set_nonblocking(handle, 1); + // send ping to USB to not time out instantly + if (isUSB) + SendRumble(rumble_obj.GetData()); + return 0; } @@ -499,23 +504,24 @@ namespace BetterJoyForCemu { xin.SendReport(report); } + // Link capture button to print screen + if (buttons[(int)Button.CAPTURE]) + WindowsInput.Simulate.Events().Click(WindowsInput.Events.KeyCode.PrintScreen).Invoke(); + if (extraGyroFeature == "joy") { // TODO } else if (extraGyroFeature == "mouse" && (isPro || (other == null) || (other != null && (Boolean.Parse(ConfigurationManager.AppSettings["GyroMouseLeftHanded"]) ? isLeft : !isLeft)))) { - Win32.POINT p; - Win32.GetCursorPos(out p); - 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)); - Win32.SetCursorPos(p.x + dx, p.y + dy); + WindowsInput.Simulate.Events().MoveBy(dx, dy).Invoke(); // reset mouse position to centre of primary monitor - if (buttons[(int) Button.STICK] || buttons[(int) Button.STICK2]) - Win32.SetCursorPos(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2); + if (buttons[(int)Button.STICK] || buttons[(int)Button.STICK2]) + WindowsInput.Simulate.Events().MoveTo(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2).Invoke(); } if (ts_en == raw_buf[1] && !isSnes) { @@ -535,21 +541,18 @@ namespace BetterJoyForCemu { Stopwatch watch = new Stopwatch(); watch.Start(); while (!stop_polling & state > state_.NO_JOYCONS) { - if (!isSnes && (isUSB || rumble_obj.t > 0)) + if (!isSnes && (rumble_obj.t > 0)) SendRumble(rumble_obj.GetData()); - else if (watch.ElapsedMilliseconds >= 1000) { - // Send a no-op operation as heartbeat to keep connection alive. - // Do not send this too frequently, otherwise I/O would be too heavy and cause lag. - // Needed for both BLUETOOTH and USB to not time out. Never remove pls - //SendRumble(rumble_obj.GetData()); - // TODO: Investigate if this really is safe to remove now? - watch.Restart(); - } + int a = ReceiveRaw(); if (a > 0) { state = state_.IMU_DATA_OK; attempts = 0; + + // Needed for USB to not time out; I think USB requires a reply message after every packet sent + if (isUSB) + SendRumble(rumble_obj.GetData()); } else if (attempts > 240) { state = state_.DROPPED; form.AppendTextBox("Dropped.\r\n"); diff --git a/BetterJoyForCemu/Program.cs b/BetterJoyForCemu/Program.cs index 3558899..817f891 100644 --- a/BetterJoyForCemu/Program.cs +++ b/BetterJoyForCemu/Program.cs @@ -53,7 +53,7 @@ namespace BetterJoyForCemu { } public void Start() { - controllerCheck = new System.Timers.Timer(5000); // check for new controllers every 5 seconds + controllerCheck = new System.Timers.Timer(2000); // check for new controllers every 2 seconds controllerCheck.Elapsed += CheckForNewControllersTime; controllerCheck.Start(); } @@ -113,8 +113,11 @@ namespace BetterJoyForCemu { while (ptr != IntPtr.Zero) { enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info)); - if (enumerate.serial_number == null) + if (enumerate.serial_number == null) { + ptr = enumerate.next; // can't believe it took me this long to figure out why USB connections used up so much CPU. + // it was getting stuck in an inf loop here! continue; + } if (form.nonOriginal) { enumerate.product_id = product_pro; diff --git a/BetterJoyForCemu/packages.config b/BetterJoyForCemu/packages.config index b62b781..fbb587f 100644 --- a/BetterJoyForCemu/packages.config +++ b/BetterJoyForCemu/packages.config @@ -5,4 +5,5 @@ + \ No newline at end of file