- Program.Main + Generic Host: Velopack hooks, settings/v1 migration, optional elevation relaunch (UAC cancel does not loop), ACL'd single instance, DI with ValidateOnBuild, global exception handlers. - Fluent window (WPF-UI 4.3): Queue, Dashboard, Settings, About pages; info bars for the v1 admin notice, games that need elevation, update ready, recovered settings. Title bar in its own row so it no longer covers the first nav item. - Game cards: Stop stays available while paused, per-step remove/move with thresholded drag and drop, keystroke steps keep their key, global vs custom timing, profiles, heatmap toggle, stop reasons in plain language. - Overlays: picker covers the game's client area on any monitor and reads the point in the game's DPI context; heatmap follows the game via WinEvents, draws only on change and is visible only while the game is in front. - Settings apply immediately; hotkey capture suspends and re-registers global hotkeys and reports conflicts; theme System/Light/Dark/High contrast; live language switch for en/vi/ja/ko/zh (279 strings each). - Dashboard samples from startup but feeds charts only while visible. - Tray (H.NotifyIcon), exit behaviors, window placement, update checks every 6 h with apply-on-exit. - --smoke-test opens every page in every theme and language plus dialogs and a heatmap, failing on any binding error; uses a temp data folder. - Architecture tests: layering, resx parity/usage, no hard-coded XAML text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
4.0 KiB
C#
140 lines
4.0 KiB
C#
using System.Globalization;
|
|
|
|
namespace AutoClick.ClickTarget;
|
|
|
|
/// <summary>
|
|
/// A plain window with no child controls, so messages posted to the top-level HWND are the
|
|
/// ones it handles. Received messages are drawn on the client area and optionally logged.
|
|
/// </summary>
|
|
internal sealed class TargetForm : Form
|
|
{
|
|
private const int WmKeyDown = 0x0100;
|
|
private const int WmKeyUp = 0x0101;
|
|
private const int WmChar = 0x0102;
|
|
private const int WmLButtonDown = 0x0201;
|
|
private const int WmLButtonUp = 0x0202;
|
|
private const int WmLButtonDblClk = 0x0203;
|
|
private const int WmRButtonDown = 0x0204;
|
|
private const int WmRButtonUp = 0x0205;
|
|
|
|
private const int MaxLines = 18;
|
|
|
|
private readonly string? _logPath;
|
|
private readonly List<string> _lines = [];
|
|
private readonly List<Point> _clicks = [];
|
|
|
|
public TargetForm(string title, string? logPath)
|
|
{
|
|
_logPath = logPath;
|
|
Text = title;
|
|
ClientSize = new Size(800, 600);
|
|
StartPosition = FormStartPosition.CenterScreen;
|
|
DoubleBuffered = true;
|
|
BackColor = Color.FromArgb(24, 24, 32);
|
|
ForeColor = Color.Gainsboro;
|
|
KeyPreview = true;
|
|
}
|
|
|
|
protected override void WndProc(ref Message m)
|
|
{
|
|
var mouse = m.Msg switch
|
|
{
|
|
WmLButtonDown => "LBUTTONDOWN",
|
|
WmLButtonUp => "LBUTTONUP",
|
|
WmLButtonDblClk => "LBUTTONDBLCLK",
|
|
WmRButtonDown => "RBUTTONDOWN",
|
|
WmRButtonUp => "RBUTTONUP",
|
|
_ => null,
|
|
};
|
|
var key = m.Msg switch
|
|
{
|
|
WmKeyDown => "KEYDOWN",
|
|
WmKeyUp => "KEYUP",
|
|
WmChar => "CHAR",
|
|
_ => null,
|
|
};
|
|
|
|
if (mouse is not null)
|
|
{
|
|
Record(mouse, m);
|
|
}
|
|
else if (key is not null)
|
|
{
|
|
RecordKey(key, m);
|
|
}
|
|
|
|
base.WndProc(ref m);
|
|
}
|
|
|
|
private void Record(string name, Message m)
|
|
{
|
|
var lParam = (long)m.LParam;
|
|
var x = (short)(lParam & 0xFFFF);
|
|
var y = (short)((lParam >> 16) & 0xFFFF);
|
|
if (name.EndsWith("DOWN", StringComparison.Ordinal))
|
|
{
|
|
_clicks.Add(new Point(x, y));
|
|
}
|
|
|
|
Append($"{name}\t{x}\t{y}\t0\t0");
|
|
}
|
|
|
|
private void RecordKey(string name, Message m)
|
|
{
|
|
var vk = (int)(long)m.WParam;
|
|
var scanCode = (int)(((long)m.LParam >> 16) & 0xFF);
|
|
Append($"{name}\t0\t0\t{vk}\t{scanCode}");
|
|
}
|
|
|
|
private void Append(string entry)
|
|
{
|
|
var line = $"{DateTime.Now.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture)}\t{entry}";
|
|
_lines.Add(line);
|
|
if (_lines.Count > MaxLines)
|
|
{
|
|
_lines.RemoveAt(0);
|
|
}
|
|
|
|
if (_logPath is not null)
|
|
{
|
|
File.AppendAllText(_logPath, line + Environment.NewLine);
|
|
}
|
|
|
|
Invalidate();
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
base.OnPaint(e);
|
|
var g = e.Graphics;
|
|
|
|
using var gridPen = new Pen(Color.FromArgb(48, 48, 64));
|
|
using var labelBrush = new SolidBrush(Color.FromArgb(110, 110, 140));
|
|
for (var x = 0; x < ClientSize.Width; x += 50)
|
|
{
|
|
g.DrawLine(gridPen, x, 0, x, ClientSize.Height);
|
|
g.DrawString(x.ToString(CultureInfo.InvariantCulture), Font, labelBrush, x + 2, 2);
|
|
}
|
|
|
|
for (var y = 50; y < ClientSize.Height; y += 50)
|
|
{
|
|
g.DrawLine(gridPen, 0, y, ClientSize.Width, y);
|
|
g.DrawString(y.ToString(CultureInfo.InvariantCulture), Font, labelBrush, 2, y + 2);
|
|
}
|
|
|
|
using var clickBrush = new SolidBrush(Color.FromArgb(200, 255, 90, 60));
|
|
foreach (var p in _clicks.TakeLast(50))
|
|
{
|
|
g.FillEllipse(clickBrush, p.X - 4, p.Y - 4, 8, 8);
|
|
}
|
|
|
|
using var textBrush = new SolidBrush(ForeColor);
|
|
var lineY = 30f;
|
|
foreach (var line in _lines)
|
|
{
|
|
g.DrawString(line, Font, textBrush, 60, lineY);
|
|
lineY += Font.Height + 2;
|
|
}
|
|
}
|
|
}
|