This commit is contained in:
辉鸭蛋
2024-12-26 02:31:23 +08:00
parent 3ed01a5d46
commit 6df528b142
8 changed files with 214 additions and 8 deletions

View File

@@ -183,6 +183,8 @@ public partial class App : Application
/// </summary>
protected override async void OnExit(ExitEventArgs e)
{
TouchpadSoft.Instance.RestoreTouchpadByHotKey();
var homePageViewModel = GetService<HomePageViewModel>();
homePageViewModel?.ResetResolution();
SysDpi.Instance.ResetDpi();

View File

@@ -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 ";
}

View File

@@ -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,

View File

@@ -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<string> { 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();
}

View File

@@ -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;
}
}

View File

@@ -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<TouchpadSoft>
{
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();
}
}
}

View File

@@ -306,6 +306,35 @@
Margin="0,0,36,0"
IsChecked="{Binding Config.CommonConfig.ProcessCheckEnabled, Mode=TwoWay}" />
</Grid>
<Separator Margin="-18,0" BorderThickness="0,1,0,0" />
<Grid Margin="16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0"
Grid.Column="0"
FontTypography="Body"
Text="ffmpeg参数"
TextWrapping="Wrap" />
<ui:TextBlock Grid.Row="1"
Grid.Column="0"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
Text="ffmpeg参数"
TextWrapping="Wrap" />
<ui:TextBox Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
MinWidth="300"
MaxWidth="800"
Margin="0,0,36,0"
Text="{Binding Config.CommonConfig.FfmpegCommand, Mode=TwoWay}"
TextWrapping="Wrap" />
</Grid>
</StackPanel>
</ui:CardExpander>

View File

@@ -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();
}