mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-17 09:26:50 +08:00
test direct input
This commit is contained in:
@@ -163,6 +163,13 @@ public partial class HotKeyConfig : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string _test1HotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 测试2
|
||||
[ObservableProperty]
|
||||
private string _test2Hotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _test2HotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
|
||||
// 日志与状态窗口展示
|
||||
[ObservableProperty]
|
||||
private string _logBoxDisplayHotkey = "";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using SharpDX.DirectInput;
|
||||
using BetterGenshinImpact.Core.Recorder;
|
||||
using SharpDX.DirectInput;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
@@ -33,8 +34,9 @@ public class DirectInputMonitor
|
||||
{
|
||||
_mouse.Acquire();
|
||||
MouseState state = _mouse.GetCurrentState();
|
||||
Debug.WriteLine($"{state.X} {state.Y} {state.Buttons[0]} {state.Buttons[1]}");
|
||||
Thread.Sleep(1000); // 10ms, equivalent to CLOCKS_PER_SEC/100
|
||||
// Debug.WriteLine($"{state.X} {state.Y} {state.Buttons[0]} {state.Buttons[1]}");
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookMouseMoveBy(state);
|
||||
Thread.Sleep(10); // 10ms, equivalent to CLOCKS_PER_SEC/100
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class MouseKeyMonitor
|
||||
private void GlobalHookMouseMoveExt(object? sender, MouseEventExtArgs e)
|
||||
{
|
||||
// Debug.WriteLine("MouseMove: {0}; \t Location: {1};\t System Timestamp: {2}", e.Button, e.Location, e.Timestamp);
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookMouseMove(e);
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookMouseMoveTo(e);
|
||||
}
|
||||
|
||||
public void Unsubscribe()
|
||||
|
||||
@@ -3,6 +3,10 @@ using System.Diagnostics;
|
||||
using BetterGenshinImpact.Model;
|
||||
using Gma.System.MouseKeyHook;
|
||||
using System.Windows.Forms;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using OpenCvSharp;
|
||||
using SharpDX.DirectInput;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder;
|
||||
|
||||
@@ -12,9 +16,15 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
|
||||
private readonly Dictionary<Keys, bool> _keyDownState = new();
|
||||
|
||||
// private Rect _captureAreaCenterRect;
|
||||
|
||||
public KeyMouseRecorder StartRecord()
|
||||
{
|
||||
_recorder = new KeyMouseRecorder();
|
||||
|
||||
// var rect = TaskContext.Instance().SystemInfo.CaptureAreaRect;
|
||||
// var centerPoint = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
|
||||
// _captureAreaCenterRect = new Rect(centerPoint.X - 10, centerPoint.Y - 15, 20, 20);
|
||||
return _recorder;
|
||||
}
|
||||
|
||||
@@ -68,9 +78,23 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
_recorder?.MouseUp(e);
|
||||
}
|
||||
|
||||
public void GlobalHookMouseMove(MouseEventExtArgs e)
|
||||
public void GlobalHookMouseMoveTo(MouseEventExtArgs e)
|
||||
{
|
||||
// if (_captureAreaCenterRect.Contains(e.X, e.Y))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// Debug.WriteLine($"MouseMove: {e.X}, {e.Y}");
|
||||
_recorder?.MouseMove(e);
|
||||
// _recorder?.MouseMoveTo(e);
|
||||
}
|
||||
|
||||
public void GlobalHookMouseMoveBy(MouseState state)
|
||||
{
|
||||
// Debug.WriteLine($"MouseMoveBy: {state.X}, {state.Y}");
|
||||
if (state is { X: 0, Y: 0 })
|
||||
{
|
||||
return;
|
||||
}
|
||||
_recorder?.MouseMoveBy(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,10 +99,14 @@ public class KeyMouseMacroPlayer
|
||||
}
|
||||
break;
|
||||
|
||||
case MacroEventType.MouseMove:
|
||||
case MacroEventType.MouseMoveTo:
|
||||
Simulation.SendInput.Mouse.MoveMouseTo(ToVirtualDesktopX(e.MouseX), ToVirtualDesktopY(e.MouseY));
|
||||
break;
|
||||
|
||||
case MacroEventType.MouseMoveBy:
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(e.MouseX, e.MouseY);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using SharpDX.DirectInput;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder;
|
||||
|
||||
@@ -77,15 +78,27 @@ public class KeyMouseRecorder
|
||||
CurrentTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public void MouseMove(MouseEventExtArgs e)
|
||||
public void MouseMoveTo(MouseEventExtArgs e)
|
||||
{
|
||||
MacroEvents.Add(new MacroEvent
|
||||
{
|
||||
Type = MacroEventType.MouseMove,
|
||||
Type = MacroEventType.MouseMoveTo,
|
||||
MouseX = e.X,
|
||||
MouseY = e.Y,
|
||||
Time = (DateTime.Now - CurrentTime).TotalMilliseconds
|
||||
});
|
||||
CurrentTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public void MouseMoveBy(MouseState state)
|
||||
{
|
||||
MacroEvents.Add(new MacroEvent
|
||||
{
|
||||
Type = MacroEventType.MouseMoveBy,
|
||||
MouseX = state.X,
|
||||
MouseY = state.Y,
|
||||
Time = (DateTime.Now - CurrentTime).TotalMilliseconds
|
||||
});
|
||||
CurrentTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ public enum MacroEventType
|
||||
{
|
||||
KeyDown,
|
||||
KeyUp,
|
||||
MouseMove,
|
||||
MouseMoveTo,
|
||||
MouseMoveBy,
|
||||
MouseDown,
|
||||
MouseUp
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ using BetterGenshinImpact.GameTask.Model.Enum;
|
||||
using static Vanara.PInvoke.User32;
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Monitor;
|
||||
using BetterGenshinImpact.Core.Recorder;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
@@ -378,6 +381,8 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
||||
(_, _) => { _taskSettingsPageViewModel.OnSwitchAutoTrackPath(); }
|
||||
));
|
||||
|
||||
var flag = false;
|
||||
var m = "";
|
||||
HotKeySettingModels.Add(new HotKeySettingModel(
|
||||
"(测试)测试",
|
||||
nameof(Config.HotKeyConfig.Test1Hotkey),
|
||||
@@ -405,22 +410,52 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
||||
// Simulation.SendInput.Mouse.MoveMouseBy(400, 0).Sleep(200)
|
||||
// .Keyboard.KeyPress(User32.VK.VK_W).Sleep(500);
|
||||
|
||||
HWND hWnd = GetForegroundWindow();
|
||||
// HWND hWnd = GetForegroundWindow();
|
||||
//
|
||||
// uint threadid = GetWindowThreadProcessId(hWnd, out var _);
|
||||
//
|
||||
// GUITHREADINFO lpgui = new GUITHREADINFO();
|
||||
// lpgui.cbSize = (uint)Marshal.SizeOf(lpgui);
|
||||
//
|
||||
// if (GetGUIThreadInfo(threadid, ref lpgui))
|
||||
// {
|
||||
// if (lpgui.hwndCaret != 0)
|
||||
// {
|
||||
// _logger.LogInformation("输入状态");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// _logger.LogInformation("非输入状态");
|
||||
|
||||
uint threadid = GetWindowThreadProcessId(hWnd, out var _);
|
||||
|
||||
GUITHREADINFO lpgui = new GUITHREADINFO();
|
||||
lpgui.cbSize = (uint)Marshal.SizeOf(lpgui);
|
||||
|
||||
if (GetGUIThreadInfo(threadid, ref lpgui))
|
||||
if (!flag)
|
||||
{
|
||||
if (lpgui.hwndCaret != 0)
|
||||
{
|
||||
_logger.LogInformation("输入状态");
|
||||
return;
|
||||
}
|
||||
GlobalKeyMouseRecord.Instance.StartRecord();
|
||||
new DirectInputMonitor().Start();
|
||||
_logger.LogInformation("开始录制脚本");
|
||||
flag = true;
|
||||
}
|
||||
_logger.LogInformation("非输入状态");
|
||||
else
|
||||
{
|
||||
m = GlobalKeyMouseRecord.Instance.StopRecord();
|
||||
Debug.WriteLine("录制脚本结束:" + m);
|
||||
_logger.LogInformation("录制脚本结束");
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
HotKeySettingModels.Add(new HotKeySettingModel(
|
||||
"(测试)测试2",
|
||||
nameof(Config.HotKeyConfig.Test2Hotkey),
|
||||
Config.HotKeyConfig.Test2Hotkey,
|
||||
Config.HotKeyConfig.Test2HotkeyType,
|
||||
(_, _) =>
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await KeyMouseMacroPlayer.PlayMacro(m);
|
||||
_logger.LogInformation("播放脚本结束");
|
||||
});
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user