diff --git a/BetterGenshinImpact/App.xaml.cs b/BetterGenshinImpact/App.xaml.cs index b29f70c4..c49ce5a0 100644 --- a/BetterGenshinImpact/App.xaml.cs +++ b/BetterGenshinImpact/App.xaml.cs @@ -183,6 +183,8 @@ public partial class App : Application /// protected override async void OnExit(ExitEventArgs e) { + TouchpadSoft.Instance.RestoreTouchpadByHotKey(); + var homePageViewModel = GetService(); homePageViewModel?.ResetResolution(); SysDpi.Instance.ResetDpi(); diff --git a/BetterGenshinImpact/Core/Config/CommonConfig.cs b/BetterGenshinImpact/Core/Config/CommonConfig.cs index 9e3f4a6f..83a5a95c 100644 --- a/BetterGenshinImpact/Core/Config/CommonConfig.cs +++ b/BetterGenshinImpact/Core/Config/CommonConfig.cs @@ -31,4 +31,7 @@ public partial class CommonConfig : ObservableObject [ObservableProperty] private bool _processCheckEnabled = true; + + [ObservableProperty] + private string _ffmpegCommand = " -f gdigrab -framerate 60 -use_wallclock_as_timestamps 1 -i title=原神 -pix_fmt yuv420p -c:v libx264 -preset ultrafast -f segment -segment_time 1800 -reset_timestamps 1 -strftime 1 "; } diff --git a/BetterGenshinImpact/Core/Video/FfmpegRecorder.cs b/BetterGenshinImpact/Core/Video/FfmpegRecorder.cs index ad23861b..13f64362 100644 --- a/BetterGenshinImpact/Core/Video/FfmpegRecorder.cs +++ b/BetterGenshinImpact/Core/Video/FfmpegRecorder.cs @@ -5,6 +5,7 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading; using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.GameTask; using BetterGenshinImpact.GameTask.Common; using Microsoft.Extensions.Logging; using Serilog.Core; @@ -39,7 +40,7 @@ public class FfmpegRecorder var processInfo = new ProcessStartInfo { FileName = FfmpegPath, - Arguments = $" -f gdigrab -framerate 60 -use_wallclock_as_timestamps 1 -i title=原神 -pix_fmt yuv420p -c:v libx264 -preset ultrafast -f segment -segment_time 1800 -reset_timestamps 1 -strftime 1 \"{_filePath}\"", + Arguments = $"{TaskContext.Instance().Config.CommonConfig.FfmpegCommand} \"{_filePath}\"", StandardInputEncoding = Encoding.UTF8, UseShellExecute = false, CreateNoWindow = true, diff --git a/BetterGenshinImpact/Helpers/Device/PCInfo.cs b/BetterGenshinImpact/Helpers/Device/PCInfo.cs index c705d89d..003c5b3a 100644 --- a/BetterGenshinImpact/Helpers/Device/PCInfo.cs +++ b/BetterGenshinImpact/Helpers/Device/PCInfo.cs @@ -12,7 +12,7 @@ public class PCInfo public 磁盘[] 磁盘 { get; set; } public 打印机[] 打印机 { get; set; } public 显卡[] 显卡 { get; set; } - + public 笔记本 笔记本 { get; set; } } @@ -127,8 +127,11 @@ subchassis (19) https://learn.microsoft.com/zh-cn/windows/win32/cimwin32prov/win32-systemenclosure */ public List 计算机类型 { get; set; } + public bool 是否笔记本 { get; set; } public bool 是否插入电源 { get; set; } - - public bool 触控板是否启用 { get; set; } = TouchpadManager.IsTouchpadPresent(); + + public bool 系统级触控板是否启用 { get; set; } = TouchpadSoft.Instance.QueryTouchpadStatus() == 1; + + public bool 是否存在触控屏 { get; set; } = TouchpadManager.HasTouchInput(); } \ No newline at end of file diff --git a/BetterGenshinImpact/Helpers/Device/TouchpadManager.cs b/BetterGenshinImpact/Helpers/Device/TouchpadManager.cs index 0f486cd0..be76040a 100644 --- a/BetterGenshinImpact/Helpers/Device/TouchpadManager.cs +++ b/BetterGenshinImpact/Helpers/Device/TouchpadManager.cs @@ -1,4 +1,6 @@ -namespace BetterGenshinImpact.Helpers.Device; +using System.Windows.Input; + +namespace BetterGenshinImpact.Helpers.Device; using System; using System.Runtime.InteropServices; @@ -98,4 +100,20 @@ public static class TouchpadManager return (digitizerStatus.ToInt32() & NID_INTEGRATED_TOUCH) != 0 || (digitizerStatus.ToInt32() & NID_EXTERNAL_TOUCH) != 0; } + + public static bool HasTouchInput() + { + foreach (TabletDevice tabletDevice in Tablet.TabletDevices) + { + //Only detect if it is a touch Screen not how many touches (i.e. Single touch or Multi-touch) + if(tabletDevice.Type == TabletDeviceType.Touch) + return true; + } + + return false; + } + + + + } \ No newline at end of file diff --git a/BetterGenshinImpact/Helpers/Device/TouchpadSoft.cs b/BetterGenshinImpact/Helpers/Device/TouchpadSoft.cs new file mode 100644 index 00000000..4b08d961 --- /dev/null +++ b/BetterGenshinImpact/Helpers/Device/TouchpadSoft.cs @@ -0,0 +1,144 @@ +using System; +using System.Runtime.InteropServices; +using BetterGenshinImpact.Core.Simulator; +using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.Model; +using Microsoft.Extensions.Logging; +using Microsoft.Win32; +using Vanara.PInvoke; + +namespace BetterGenshinImpact.Helpers.Device; + +public class TouchpadSoft : Singleton +{ + private const string TouchpadRegistryPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\PrecisionTouchPad\Status"; + private const string TouchpadRegistryKey = "Enabled"; + private int? previousStatus = null; + + // 获取触控板状态的方法 + private int GetTouchpadStatus() + { + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(TouchpadRegistryPath, true)) + { + if (key != null) + { + object value = key.GetValue(TouchpadRegistryKey); + if (value != null) + { + return (int)value; + } + else + { + // 如果键值不存在,则写入默认值1(启用触控板) + key.SetValue(TouchpadRegistryKey, 1, RegistryValueKind.DWord); + return 1; + } + } + else + { + throw new InvalidOperationException("Registry path not found."); + } + } + } + + // 设置触控板状态的方法 + private void SetTouchpadStatus(int status) + { + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(TouchpadRegistryPath, true)) + { + if (key != null) + { + key.SetValue(TouchpadRegistryKey, status, RegistryValueKind.DWord); + } + else + { + throw new InvalidOperationException("Registry path not found."); + } + } + } + + // 只查询触控板状态的方法 + public int QueryTouchpadStatus() + { + return GetTouchpadStatus(); + } + + // 检查并记录触控板状态的方法 + public void CheckAndRecordStatus() + { + previousStatus = GetTouchpadStatus(); + Console.WriteLine("Current Touchpad Status: " + previousStatus); + } + + // 关闭触控板的方法 + public void DisableTouchpad() + { + SetTouchpadStatus(0); + Console.WriteLine("Touchpad has been disabled."); + } + + // 还原触控板状态的方法 + public void RestoreTouchpad() + { + if (previousStatus.HasValue) + { + SetTouchpadStatus(previousStatus.Value); + Console.WriteLine("Touchpad status has been restored to: " + previousStatus.Value); + } + else + { + Console.WriteLine("No previous status recorded."); + } + } + + [Flags] + public enum SendMessageTimeoutFlags : uint + { + SMTO_NORMAL = 0x0, + SMTO_BLOCK = 0x1, + SMTO_ABORTIFHUNG = 0x2, + SMTO_NOTIMEOUTIFNOTHUNG = 0x8 + } + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam, + SendMessageTimeoutFlags fuFlags, uint uTimeout, out UIntPtr lpdwResult); + + + IntPtr HWND_BROADCAST = new IntPtr(0xffff); + const uint WM_SETTINGCHANGE = 0x1A; + const int MSG_TIMEOUT = 15000; + UIntPtr RESULT; + string ENVIRONMENT = "Environment"; + + public void NotifySettingChange() + { + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, UIntPtr.Zero, (IntPtr)Marshal.StringToHGlobalAnsi(ENVIRONMENT), SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, MSG_TIMEOUT, out RESULT); + } + + public void SwitchTouchpadByHotKey() + { + Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_LCONTROL); + Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_LWIN); + Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_F24); + Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_F24); + Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_LWIN); + Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_LCONTROL); + } + + public void DisableTouchpadWhenEnabledByHotKey() + { + if (previousStatus == 1) + { + SwitchTouchpadByHotKey(); + } + } + + public void RestoreTouchpadByHotKey() + { + if (previousStatus == 1) + { + SwitchTouchpadByHotKey(); + } + } +} \ No newline at end of file diff --git a/BetterGenshinImpact/View/Pages/HomePage.xaml b/BetterGenshinImpact/View/Pages/HomePage.xaml index 07767ccb..a676feba 100644 --- a/BetterGenshinImpact/View/Pages/HomePage.xaml +++ b/BetterGenshinImpact/View/Pages/HomePage.xaml @@ -306,6 +306,35 @@ Margin="0,0,36,0" IsChecked="{Binding Config.CommonConfig.ProcessCheckEnabled, Mode=TwoWay}" /> + + + + + + + + + + + + + + diff --git a/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs b/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs index 3a9a9f5b..7c2ed8f3 100644 --- a/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs +++ b/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs @@ -128,9 +128,10 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel EnvironmentUtil.PrintMouseSettings(); - - // 设置DPI - SysDpi.Instance.SetDpi(); + + + TouchpadSoft.Instance.CheckAndRecordStatus(); + TouchpadSoft.Instance.DisableTouchpadWhenEnabledByHotKey(); try { @@ -142,6 +143,11 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel { _logger.LogError("获取PC信息失败:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message); } + + + + // 设置DPI + SysDpi.Instance.SetDpi(); }