This commit is contained in:
辉鸭蛋
2024-12-16 23:56:30 +08:00
parent e6bac7e72c
commit 83f8f78203
8 changed files with 47 additions and 43 deletions

View File

@@ -207,10 +207,10 @@ public partial class HotKeyConfig : ObservableObject
// 键鼠录制/停止
[ObservableProperty]
private string _keyMouseMacroRecordHotkey = "";
private string _keyMouseMacroRecordHotkey = "Ctrl + K";
[ObservableProperty]
private string _keyMouseMacroRecordHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
private string _keyMouseMacroRecordHotkeyType = HotKeyTypeEnum.GlobalRegister.ToString();
// 停止任意独立任务
[ObservableProperty]

View File

@@ -46,7 +46,7 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
_timer.Interval = 50; // ms
}
public async Task StartRecord()
public async Task StartRecord(string fileName)
{
if (!TaskContext.Instance().IsInitialized)
{
@@ -64,35 +64,31 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
SystemControl.ActivateWindow();
_logger.LogInformation("录制:{Text}", "实时任务已暂停");
// _logger.LogInformation("录制:{Text}", "实时任务已暂停");
// _logger.LogInformation("注意:录制时遇到主界面(鼠标永远在界面中心)和其他界面(鼠标可自由移动,比如地图等)的切换,请把手离开鼠标等待录制模式切换日志");
// 先实例化
_recorder = new KeyMouseRecorder();
_directInputMonitor = new DirectInputMonitor();
var videoPath = Global.Absolute(@"video");
if (!Directory.Exists(videoPath))
{
Directory.CreateDirectory(videoPath);
}
// _sharpAviRecorder = new SharpAviRecorder( Path.Combine(videoPath, $"{DateTime.Now:yyyyMMddHH_mmssffff.avi}"),
// CodecIds.MotionJpeg, 90, 0, SupportedWaveFormat.WAVE_FORMAT_44M16, false, 0);
_ffmpegRecorder = new FfmpegRecorder();
_ffmpegRecorder = new FfmpegRecorder(fileName);
_directInputMonitor = new DirectInputMonitor();
TaskTriggerDispatcher.Instance().StopTimer();
// TaskTriggerDispatcher.Instance().StopTimer();
for (var i = 3; i >= 1; i--)
{
_logger.LogInformation("{Sec}秒后启动录制...", i);
await Task.Delay(1000);
}
// for (var i = 3; i >= 1; i--)
// {
// _logger.LogInformation("{Sec}秒后启动录制...", i);
// await Task.Delay(1000);
// }
// _timer.Start();
_ffmpegRecorder.Start();
_directInputMonitor.Start();
_recorder = new KeyMouseRecorder();
Status = KeyMouseRecorderStatus.Recording;
@@ -118,7 +114,7 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
_logger.LogInformation("录制:{Text}", "结束录制");
TaskTriggerDispatcher.Instance().StartTimer();
// TaskTriggerDispatcher.Instance().StartTimer();
Status = KeyMouseRecorderStatus.Stop;
@@ -127,7 +123,7 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
public void Tick(object? sender, EventArgs e)
{
var ra = TaskControl.CaptureToRectArea();
var ra = TaskControl.CaptureToRectArea(true);
var iconRa = ra.Find(ElementAssets.Instance.FriendChat);
var exist = iconRa.IsExist();
if (exist != _isInMainUi)

View File

@@ -34,7 +34,7 @@ public class KeyMouseMacroPlayer
if (withDelay)
{
for (var i = 3; i >= 1; i--)
for (var i = 1; i >= 1; i--)
{
TaskControl.Logger.LogInformation("{Sec}秒后进行重放...", i);
await Task.Delay(1000, ct);

View File

@@ -17,9 +17,10 @@ public class KeyMouseRecorder
{
public List<MacroEvent> MacroEvents { get; } = [];
public List<MacroEvent> MouseMoveToMacroEvents { get; } = [];
public List<MacroEvent> MouseMoveByMacroEvents { get; } = [];
public DateTime StartTime { get; set; } = DateTime.UtcNow;
public DateTime StartTime { get; set; } = DateTime.UtcNow;
public DateTime LastOrientationDetection { get; set; } = DateTime.UtcNow;
@@ -156,13 +157,15 @@ public class KeyMouseRecorder
public void MouseMoveTo(MouseEventExtArgs e)
{
MacroEvents.Add(new MacroEvent
var mEvent = new MacroEvent
{
Type = MacroEventType.MouseMoveTo,
MouseX = e.X,
MouseY = e.Y,
Time = (DateTime.UtcNow - StartTime).TotalMilliseconds
});
};
MouseMoveToMacroEvents.Add(mEvent);
MacroEvents.Add(mEvent);
}
public void MouseWheel(MouseEventExtArgs e)

View File

@@ -22,15 +22,18 @@ public class FfmpegRecorder
private readonly string _filePath;
private string _startTime = string.Empty;
private readonly string _fileName;
public FfmpegRecorder()
public FfmpegRecorder(string fileName)
{
_fileName = fileName;
if (!File.Exists(FfmpegPath))
{
throw new Exception("ffmpeg.exe不存在");
}
_filePath = Global.Absolute($@"video\{DateTime.Now:yyyyMMddHH_mmssffff}.mp4");
_filePath = Global.Absolute($@"video\{fileName}.mp4");
var processInfo = new ProcessStartInfo
{
FileName = FfmpegPath,
@@ -57,7 +60,7 @@ public class FfmpegRecorder
Match match = Regex.Match(args.Data, pattern);
if (match.Success)
{
_startTime = match.Groups[1].Value;
_startTime = match.Groups[1].Value.Replace(".", "");
TaskControl.Logger.LogInformation("ffmpeg录制: 视频起始时间戳 {Text}", _startTime);
}
}
@@ -108,7 +111,7 @@ public class FfmpegRecorder
if (File.Exists(_filePath))
{
// 重命名文件
var newFilePath = Global.Absolute($@"video\{_startTime}.mp4");
var newFilePath = Global.Absolute($@"video\{_fileName}_{_startTime}.mp4");
File.Move(_filePath, newFilePath);
TaskControl.Logger.LogInformation("ffmpeg录制: {Text}", $"录制完成");
}

View File

@@ -129,7 +129,7 @@ namespace BetterGenshinImpact.GameTask
public void Start(IntPtr hWnd, CaptureModes mode, int interval = 50)
{
// 初始化截图器
// GameCapture = GameCaptureFactory.Create(mode);
GameCapture = GameCaptureFactory.Create(mode);
// 激活窗口 保证后面能够正常获取窗口信息
SystemControl.ActivateWindow(hWnd);
@@ -140,13 +140,13 @@ namespace BetterGenshinImpact.GameTask
_triggers = [];
// 启动截图
// GameCapture.Start(hWnd,
// new Dictionary<string, object>()
// {
// { "useBitmapCache", TaskContext.Instance().Config.WgcUseBitmapCache },
// { "autoFixWin11BitBlt", OsVersionHelper.IsWindows11_OrGreater && TaskContext.Instance().Config.AutoFixWin11BitBlt }
// }
// );
GameCapture.Start(hWnd,
new Dictionary<string, object>()
{
{ "useBitmapCache", TaskContext.Instance().Config.WgcUseBitmapCache },
{ "autoFixWin11BitBlt", OsVersionHelper.IsWindows11_OrGreater && TaskContext.Instance().Config.AutoFixWin11BitBlt }
}
);
// 捕获模式初始化配置
// if (TaskContext.Instance().Config.CommonConfig.ScreenshotEnabled || TaskContext.Instance().Config.MacroConfig.CombatMacroEnabled)

View File

@@ -548,7 +548,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
// }
// ));
FfmpegRecorder ffmpegRecorder = new FfmpegRecorder();
// FfmpegRecorder ffmpegRecorder = new FfmpegRecorder();
debugDirectory.Children.Add(new HotKeySettingModel(
"(测试)测试",
nameof(Config.HotKeyConfig.Test1Hotkey),
@@ -580,7 +580,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
// 拾取物品
// Task.Run(async () => { await new ScanPickTask().Start(new CancellationToken()); });
ffmpegRecorder.Start();
// ffmpegRecorder.Start();
}
));
debugDirectory.Children.Add(new HotKeySettingModel(
@@ -592,7 +592,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
{
// GoToCraftingBenchTask goToCraftingBenchTask = new GoToCraftingBenchTask();
// Task.Run(async () => { await goToCraftingBenchTask.Start("璃月", new CancellationToken()); });
ffmpegRecorder.Stop();
// ffmpegRecorder.Stop();
}
));

View File

@@ -36,6 +36,8 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
private readonly ISnackbarService _snackbarService;
public AllConfig Config { get; set; }
string fileName = $"{DateTime.Now:yyyyMMddHH_mmssffff}";
public KeyMouseRecordPageViewModel(ISnackbarService snackbarService, IConfigService configService)
{
@@ -67,8 +69,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
Directory.CreateDirectory(folder);
}
var files = Directory.GetFiles(folder, "*.*",
SearchOption.AllDirectories);
var files = Directory.GetFiles(folder, "*.json", SearchOption.TopDirectoryOnly);
return files.Select(file => new FileInfo(file)).ToList();
}
@@ -93,7 +94,8 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
if (!IsRecording)
{
IsRecording = true;
await GlobalKeyMouseRecord.Instance.StartRecord();
fileName = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss:ffff}";
await GlobalKeyMouseRecord.Instance.StartRecord(fileName);
}
}
@@ -106,7 +108,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
{
var macro = GlobalKeyMouseRecord.Instance.StopRecord();
// Genshin Copilot Macro
File.WriteAllText(Path.Combine(scriptPath, $"BetterGI_GCM_{DateTime.Now:yyyyMMddHHmmssffff}.json"), macro);
File.WriteAllText(Path.Combine(scriptPath, $"BetterGI_GCM_{fileName}.json"), macro);
// 刷新ListView
InitScriptListViewData();
IsRecording = false;