mod: 为连发功能提供改键支持

This commit is contained in:
Ayu0K
2025-01-04 21:23:03 +08:00
parent 60ccbfbace
commit 2db2c1957a
2 changed files with 37 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Windows.Forms;
using System.Windows.Input;
using Windows.Networking.PushNotifications;
using static Vanara.PInvoke.User32;
namespace BetterGenshinImpact.Core.Config;
@@ -490,6 +492,22 @@ public static class KeyIdConverter
};
}
/// <summary>
/// [实验] 将KeyId转换为WinForm中的Keys用于兼容按键连发功能
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Keys ToWinFormKeys(this KeyId value)
{
try
{
return Enum.Parse<Keys>(value.ToInputKey().ToString());
}
catch
{
return default;
}
}
/// <summary>
/// 将VK转换为KeyId

View File

@@ -1,4 +1,5 @@
using BetterGenshinImpact.Core.Recorder;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recorder;
using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.Model;
@@ -18,6 +19,10 @@ public class MouseKeyMonitor
/// </summary>
private readonly Timer _fTimer = new();
private Keys _pickUpKey = Keys.F;
private User32.VK _pickUpKeyCode = User32.VK.VK_F;
//private readonly Random _random = new();
/// <summary>
@@ -25,6 +30,10 @@ public class MouseKeyMonitor
/// </summary>
private readonly Timer _spaceTimer = new();
private Keys _releaseControlKey = Keys.Space;
private User32.VK _releaseControlKeyCode = User32.VK.VK_SPACE;
private DateTime _firstFKeyDownTime = DateTime.MaxValue;
/// <summary>
@@ -49,14 +58,19 @@ public class MouseKeyMonitor
_globalHook.MouseWheelExt += GlobalHookMouseWheelExt;
//_globalHook.KeyPress += GlobalHookKeyPress;
_pickUpKey = TaskContext.Instance().Config.KeyBindingsConfig.PickUpOrInteract.ToWinFormKeys();
_pickUpKeyCode = TaskContext.Instance().Config.KeyBindingsConfig.PickUpOrInteract.ToVK();
_releaseControlKey = TaskContext.Instance().Config.KeyBindingsConfig.Jump.ToWinFormKeys();
_releaseControlKeyCode = TaskContext.Instance().Config.KeyBindingsConfig.Jump.ToVK();
_firstSpaceKeyDownTime = DateTime.MaxValue;
var si = TaskContext.Instance().Config.MacroConfig.SpaceFireInterval;
_spaceTimer.Interval = si;
_spaceTimer.Elapsed += (sender, args) => { Simulation.PostMessage(_hWnd).KeyPress(User32.VK.VK_SPACE); };
_spaceTimer.Elapsed += (sender, args) => { Simulation.PostMessage(_hWnd).KeyPress(_releaseControlKeyCode); };
var fi = TaskContext.Instance().Config.MacroConfig.FFireInterval;
_fTimer.Interval = fi;
_fTimer.Elapsed += (sender, args) => { Simulation.PostMessage(_hWnd).KeyPress(User32.VK.VK_F); };
_fTimer.Elapsed += (sender, args) => { Simulation.PostMessage(_hWnd).KeyPress(_pickUpKeyCode); };
}
private void GlobalHookKeyDown(object? sender, KeyEventArgs e)
@@ -67,7 +81,7 @@ public class MouseKeyMonitor
// 热键按下事件
HotKeyDown(sender, e);
if (e.KeyCode == Keys.Space)
if (e.KeyCode == _releaseControlKey)
{
if (_firstSpaceKeyDownTime == DateTime.MaxValue)
{
@@ -81,7 +95,7 @@ public class MouseKeyMonitor
_spaceTimer.Start();
}
}
else if (e.KeyCode == Keys.F)
else if (e.KeyCode == _pickUpKey)
{
if (_firstFKeyDownTime == DateTime.MaxValue)
{