Files
better-genshin-impact/BetterGenshinImpact/Core/Simulator/Simulation.cs
2025-01-01 19:34:39 +08:00

41 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Fischless.WindowsInput;
using System;
using BetterGenshinImpact.GameTask.Common;
using Microsoft.Extensions.Logging;
using Vanara.PInvoke;
namespace BetterGenshinImpact.Core.Simulator;
public class Simulation
{
public static InputSimulator SendInput { get; } = new();
public static MouseEventSimulator MouseEvent { get; } = new();
public static PostMessageSimulator PostMessage(IntPtr hWnd)
{
return new PostMessageSimulator(hWnd);
}
public static void ReleaseAllKey()
{
foreach (User32.VK key in Enum.GetValues(typeof(User32.VK)))
{
// 检查键是否被按下
if (IsKeyDown(key)) // 强制转换 VK 枚举为 int
{
TaskControl.Logger.LogDebug($"解除{key}的按下状态.");
SendInput.Keyboard.KeyUp(key);
}
}
}
private static bool IsKeyDown(User32.VK key)
{
// 获取按键状态
var state = User32.GetAsyncKeyState((int)key);
// 检查高位是否为 1表示按键被按下
return (state & 0x8000) != 0;
}
}