using System; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Windows.Forms; namespace AutoMouse { internal static class Native { public const int WH_KEYBOARD_LL = 13; public const int WH_MOUSE_LL = 14; public const int WM_KEYDOWN = 0x0100; public const int WM_SYSKEYDOWN = 0x0104; public const int WM_LBUTTONDOWN = 0x0201; public const int WM_LBUTTONUP = 0x0202; public const int WM_RBUTTONDOWN = 0x0204; public const int WM_RBUTTONUP = 0x0205; public const int WM_MBUTTONDOWN = 0x0207; public const int WM_MBUTTONUP = 0x0208; public const int WM_XBUTTONDOWN = 0x020B; public const int WM_XBUTTONUP = 0x020C; public const uint LLMHF_INJECTED = 0x00000001; // 우리가 SendInput 으로 만든 클릭을 후킹에서 걸러내기 위한 표식 public static readonly IntPtr SELF_TAG = new IntPtr(0x4D415345); public const uint INPUT_MOUSE = 0; public const uint MOUSEEVENTF_LEFTDOWN = 0x0002; public const uint MOUSEEVENTF_LEFTUP = 0x0004; public const uint MOUSEEVENTF_RIGHTDOWN = 0x0008; public const uint MOUSEEVENTF_RIGHTUP = 0x0010; public const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020; public const uint MOUSEEVENTF_MIDDLEUP = 0x0040; [StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT { public int dx; public int dy; public uint mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; } [StructLayout(LayoutKind.Sequential)] public struct INPUT { public uint type; public MOUSEINPUT mi; } [StructLayout(LayoutKind.Sequential)] public struct POINT { public int x; public int y; } [StructLayout(LayoutKind.Sequential)] public struct MSLLHOOKSTRUCT { public POINT pt; public uint mouseData; public uint flags; public uint time; public IntPtr dwExtraInfo; } public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr GetModuleHandle(string lpModuleName); [DllImport("user32.dll", SetLastError = true)] public static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetCursorPos(int x, int y); } public class MainForm : Form { // ---- 설정 컨트롤 ---- private NumericUpDown numInterval; private Label lblCps; private NumericUpDown numHold; private NumericUpDown numJitter; private ComboBox cboButton; private ComboBox cboClickType; private NumericUpDown numRepeat; private RadioButton rdoCursor; private RadioButton rdoFixed; private NumericUpDown numX; private NumericUpDown numY; private Button btnPickPos; private TextBox txtHotkey; private Button btnSetHotkey; private CheckBox chkTopMost; private Button btnToggle; private Label lblStatus; private Label lblCount; // ---- 상태 ---- private IntPtr hookId = IntPtr.Zero; private IntPtr mouseHookId = IntPtr.Zero; private Native.LowLevelKeyboardProc hookProc; // GC 방지용 필드 private Native.LowLevelKeyboardProc mouseHookProc; // GC 방지용 필드 // 트리거: 키보드 키 또는 마우스 버튼 중 하나 private const int MB_RIGHT = 1, MB_MIDDLE = 2, MB_X1 = 3, MB_X2 = 4; private Keys hotkey = Keys.F6; private int triggerMouse = 0; // 0 이면 키보드 트리거 사용 private bool capturingHotkey = false; private int swallowUpFor = 0; // 눌림을 가로챈 마우스 버튼의 뗌 이벤트도 가로채기 위함 private volatile bool running = false; private volatile int generation = 0; // Start 할 때마다 증가 private Thread worker; private long clickCount = 0; private readonly Random rnd = new Random(); private System.Windows.Forms.Timer uiTimer; private readonly string configPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "automouse.ini"); public MainForm() { BuildUi(); LoadConfig(); UpdateCps(); UpdateHotkeyText(); UpdateStatus(); hookProc = HookCallback; mouseHookProc = MouseHookCallback; InstallHooks(); uiTimer = new System.Windows.Forms.Timer(); uiTimer.Interval = 100; uiTimer.Tick += delegate { lblCount.Text = "클릭 수: " + Interlocked.Read(ref clickCount).ToString("N0"); }; uiTimer.Start(); } private void BuildUi() { Text = "오토 마우스"; FormBorderStyle = FormBorderStyle.FixedSingle; MaximizeBox = false; StartPosition = FormStartPosition.CenterScreen; ClientSize = new Size(360, 484); Font = new Font("맑은 고딕", 9f); int y = 12; const int lx = 14, cx = 130, w = 100; AddLabel("클릭 간격 (ms)", lx, y + 4); numInterval = new NumericUpDown(); numInterval.Location = new Point(cx, y); numInterval.Size = new Size(w, 24); numInterval.Minimum = 1; numInterval.Maximum = 3600000; numInterval.Value = 100; numInterval.ValueChanged += delegate { UpdateCps(); }; Controls.Add(numInterval); lblCps = new Label(); lblCps.Location = new Point(cx + w + 8, y + 4); lblCps.AutoSize = true; lblCps.ForeColor = Color.DimGray; Controls.Add(lblCps); y += 32; AddLabel("누름 유지 (ms)", lx, y + 4); numHold = new NumericUpDown(); numHold.Location = new Point(cx, y); numHold.Size = new Size(w, 24); numHold.Minimum = 0; numHold.Maximum = 5000; numHold.Value = 30; Controls.Add(numHold); AddHint("게임은 30↑", cx + w + 8, y + 4); y += 32; AddLabel("랜덤 편차 (%)", lx, y + 4); numJitter = new NumericUpDown(); numJitter.Location = new Point(cx, y); numJitter.Size = new Size(w, 24); numJitter.Minimum = 0; numJitter.Maximum = 90; numJitter.Value = 0; Controls.Add(numJitter); y += 32; AddLabel("마우스 버튼", lx, y + 4); cboButton = new ComboBox(); cboButton.Location = new Point(cx, y); cboButton.Size = new Size(w, 24); cboButton.DropDownStyle = ComboBoxStyle.DropDownList; cboButton.Items.AddRange(new object[] { "왼쪽", "오른쪽", "가운데" }); cboButton.SelectedIndex = 0; Controls.Add(cboButton); y += 32; AddLabel("클릭 방식", lx, y + 4); cboClickType = new ComboBox(); cboClickType.Location = new Point(cx, y); cboClickType.Size = new Size(w, 24); cboClickType.DropDownStyle = ComboBoxStyle.DropDownList; cboClickType.Items.AddRange(new object[] { "싱글 클릭", "더블 클릭" }); cboClickType.SelectedIndex = 0; Controls.Add(cboClickType); y += 32; AddLabel("반복 횟수", lx, y + 4); numRepeat = new NumericUpDown(); numRepeat.Location = new Point(cx, y); numRepeat.Size = new Size(w, 24); numRepeat.Minimum = 0; numRepeat.Maximum = 100000000; numRepeat.Value = 0; Controls.Add(numRepeat); AddHint("0 = 무한", cx + w + 8, y + 4); y += 36; GroupBox grp = new GroupBox(); grp.Text = "클릭 위치"; grp.Location = new Point(lx, y); grp.Size = new Size(332, 78); rdoCursor = new RadioButton(); rdoCursor.Text = "현재 커서 위치"; rdoCursor.Location = new Point(12, 22); rdoCursor.AutoSize = true; rdoCursor.Checked = true; grp.Controls.Add(rdoCursor); rdoFixed = new RadioButton(); rdoFixed.Text = "고정 좌표"; rdoFixed.Location = new Point(12, 48); rdoFixed.AutoSize = true; grp.Controls.Add(rdoFixed); numX = new NumericUpDown(); numX.Location = new Point(110, 45); numX.Size = new Size(64, 24); numX.Minimum = -32000; numX.Maximum = 32000; grp.Controls.Add(numX); numY = new NumericUpDown(); numY.Location = new Point(180, 45); numY.Size = new Size(64, 24); numY.Minimum = -32000; numY.Maximum = 32000; grp.Controls.Add(numY); btnPickPos = new Button(); btnPickPos.Text = "현재 위치"; btnPickPos.Location = new Point(250, 44); btnPickPos.Size = new Size(70, 26); btnPickPos.Click += delegate { Point p = Cursor.Position; numX.Value = Math.Max(numX.Minimum, Math.Min(numX.Maximum, p.X)); numY.Value = Math.Max(numY.Minimum, Math.Min(numY.Maximum, p.Y)); rdoFixed.Checked = true; }; grp.Controls.Add(btnPickPos); Controls.Add(grp); y += 88; AddLabel("시작/정지 키", lx, y + 4); txtHotkey = new TextBox(); txtHotkey.Location = new Point(cx, y); txtHotkey.Size = new Size(w, 24); txtHotkey.ReadOnly = true; txtHotkey.TextAlign = HorizontalAlignment.Center; Controls.Add(txtHotkey); btnSetHotkey = new Button(); btnSetHotkey.Text = "변경"; btnSetHotkey.Location = new Point(cx + w + 8, y - 1); btnSetHotkey.Size = new Size(80, 26); btnSetHotkey.Click += delegate { BeginCapture(); }; Controls.Add(btnSetHotkey); y += 28; AddHint("변경 후 키 또는 마우스 버튼(우클릭·휠·옆버튼)을 누르세요", lx, y); y += 22; chkTopMost = new CheckBox(); chkTopMost.Text = "항상 위에 표시"; chkTopMost.Location = new Point(lx, y); chkTopMost.AutoSize = true; chkTopMost.CheckedChanged += delegate { TopMost = chkTopMost.Checked; }; Controls.Add(chkTopMost); y += 30; btnToggle = new Button(); btnToggle.Location = new Point(lx, y); btnToggle.Size = new Size(332, 40); btnToggle.Font = new Font("맑은 고딕", 11f, FontStyle.Bold); btnToggle.Click += delegate { Toggle(); }; Controls.Add(btnToggle); y += 48; lblStatus = new Label(); lblStatus.Location = new Point(lx, y); lblStatus.AutoSize = true; lblStatus.Font = new Font("맑은 고딕", 10f, FontStyle.Bold); Controls.Add(lblStatus); lblCount = new Label(); lblCount.Location = new Point(lx + 200, y + 1); lblCount.AutoSize = true; lblCount.ForeColor = Color.DimGray; lblCount.Text = "클릭 수: 0"; Controls.Add(lblCount); } private void AddLabel(string text, int x, int y) { Label l = new Label(); l.Text = text; l.Location = new Point(x, y); l.AutoSize = true; Controls.Add(l); } private void AddHint(string text, int x, int y) { Label l = new Label(); l.Text = text; l.Location = new Point(x, y); l.AutoSize = true; l.ForeColor = Color.DimGray; Controls.Add(l); } private void UpdateCps() { double ms = (double)numInterval.Value; lblCps.Text = "= 초당 " + (1000.0 / ms).ToString("0.##") + "회"; } private void UpdateHotkeyText() { txtHotkey.Text = capturingHotkey ? "키 / 마우스 입력..." : TriggerName(); } private string TriggerName() { switch (triggerMouse) { case MB_RIGHT: return "마우스 우클릭"; case MB_MIDDLE: return "마우스 휠클릭"; case MB_X1: return "마우스 옆버튼1"; case MB_X2: return "마우스 옆버튼2"; default: return KeyName(hotkey); } } private static string KeyName(Keys k) { if (k >= Keys.D0 && k <= Keys.D9) return ((char)('0' + (k - Keys.D0))).ToString(); if (k >= Keys.NumPad0 && k <= Keys.NumPad9) return "숫자패드 " + (k - Keys.NumPad0); return k.ToString(); } private void UpdateStatus() { if (running) { lblStatus.Text = "● 실행 중"; lblStatus.ForeColor = Color.Firebrick; btnToggle.Text = "정지 (" + TriggerName() + ")"; } else { lblStatus.Text = "○ 대기 중"; lblStatus.ForeColor = Color.SeaGreen; btnToggle.Text = "시작 (" + TriggerName() + ")"; } } private void BeginCapture() { InstallHooks(); capturingHotkey = true; UpdateHotkeyText(); btnSetHotkey.Enabled = false; } private void EndCaptureKey(Keys k, bool cancelled) { capturingHotkey = false; if (!cancelled) { hotkey = k; triggerMouse = 0; } btnSetHotkey.Enabled = true; UpdateHotkeyText(); UpdateStatus(); SaveConfig(); } private void EndCaptureMouse(int mb) { capturingHotkey = false; triggerMouse = mb; btnSetHotkey.Enabled = true; UpdateHotkeyText(); UpdateStatus(); SaveConfig(); } // 후킹을 (다시) 설치한다. Windows 는 응답이 늦은 저수준 후킹을 알림 없이 제거하므로, // 단축키를 새로 지정할 때마다 다시 걸어 두면 혹시 떨어진 후킹도 복구된다. private void InstallHooks() { UninstallHooks(); IntPtr hMod = Native.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName); hookId = Native.SetWindowsHookEx(Native.WH_KEYBOARD_LL, hookProc, hMod, 0); mouseHookId = Native.SetWindowsHookEx(Native.WH_MOUSE_LL, mouseHookProc, hMod, 0); } private void UninstallHooks() { if (hookId != IntPtr.Zero) { Native.UnhookWindowsHookEx(hookId); hookId = IntPtr.Zero; } if (mouseHookId != IntPtr.Zero) { Native.UnhookWindowsHookEx(mouseHookId); mouseHookId = IntPtr.Zero; } } // ---- 전역 키보드 후킹 ---- private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && (wParam == (IntPtr)Native.WM_KEYDOWN || wParam == (IntPtr)Native.WM_SYSKEYDOWN)) { Keys vk = (Keys)Marshal.ReadInt32(lParam); if (capturingHotkey) { if (!IsModifier(vk)) { bool cancel = (vk == Keys.Escape); BeginInvoke(new Action(delegate { EndCaptureKey(vk, cancel); })); return (IntPtr)1; // 캡처 중인 키는 다른 프로그램으로 전달하지 않음 } } else if (triggerMouse == 0 && vk == hotkey) { BeginInvoke(new Action(Toggle)); } } return Native.CallNextHookEx(hookId, nCode, wParam, lParam); } // ---- 전역 마우스 후킹 (마우스 버튼을 시작/정지 트리거로 사용) ---- private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { int msg = wParam.ToInt32(); bool isDown = msg == Native.WM_RBUTTONDOWN || msg == Native.WM_MBUTTONDOWN || msg == Native.WM_XBUTTONDOWN || msg == Native.WM_LBUTTONDOWN; bool isUp = msg == Native.WM_RBUTTONUP || msg == Native.WM_MBUTTONUP || msg == Native.WM_XBUTTONUP || msg == Native.WM_LBUTTONUP; if (isDown || isUp) { Native.MSLLHOOKSTRUCT data = (Native.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Native.MSLLHOOKSTRUCT)); // 이 프로그램이 만들어낸 클릭은 무시 (자기 자신을 토글하지 않도록) bool self = data.dwExtraInfo == Native.SELF_TAG || (data.flags & Native.LLMHF_INJECTED) != 0; if (!self) { int mb = MouseButtonOf(msg, data.mouseData); if (isUp && mb != 0 && mb == swallowUpFor) { swallowUpFor = 0; return (IntPtr)1; // 눌림을 가로챘으므로 뗌도 함께 가로챔 } if (isDown && mb != 0) { if (capturingHotkey) { // 왼쪽 버튼은 UI 조작에 필요하므로 트리거로 허용하지 않음 if (msg != Native.WM_LBUTTONDOWN) { int picked = mb; BeginInvoke(new Action(delegate { EndCaptureMouse(picked); })); swallowUpFor = mb; return (IntPtr)1; } } else if (triggerMouse != 0 && mb == triggerMouse) { BeginInvoke(new Action(Toggle)); swallowUpFor = mb; return (IntPtr)1; // 원래 동작(예: 컨텍스트 메뉴)은 막음 } } } } } return Native.CallNextHookEx(mouseHookId, nCode, wParam, lParam); } private static int MouseButtonOf(int msg, uint mouseData) { switch (msg) { case Native.WM_RBUTTONDOWN: case Native.WM_RBUTTONUP: return MB_RIGHT; case Native.WM_MBUTTONDOWN: case Native.WM_MBUTTONUP: return MB_MIDDLE; case Native.WM_XBUTTONDOWN: case Native.WM_XBUTTONUP: return ((mouseData >> 16) & 0xFFFF) == 2 ? MB_X2 : MB_X1; default: return 0; } } private static bool IsModifier(Keys k) { return k == Keys.ShiftKey || k == Keys.LShiftKey || k == Keys.RShiftKey || k == Keys.ControlKey || k == Keys.LControlKey || k == Keys.RControlKey || k == Keys.Menu || k == Keys.LMenu || k == Keys.RMenu || k == Keys.LWin || k == Keys.RWin; } // ---- 시작 / 정지 ---- private void Toggle() { if (running) Stop(); else Start(); } private void Start() { if (running) return; int gen = ++generation; int interval = (int)numInterval.Value; int hold = (int)numHold.Value; int jitter = (int)numJitter.Value; long limit = (long)numRepeat.Value; int btnIndex = cboButton.SelectedIndex; bool dbl = cboClickType.SelectedIndex == 1; bool useFixed = rdoFixed.Checked; int px = (int)numX.Value; int py = (int)numY.Value; Interlocked.Exchange(ref clickCount, 0); running = true; UpdateStatus(); SaveConfig(); worker = new Thread(delegate () { Run(gen, interval, hold, jitter, limit, btnIndex, dbl, useFixed, px, py); }); worker.IsBackground = true; worker.Priority = ThreadPriority.AboveNormal; worker.Start(); } // 작업 스레드를 기다리지 않는다(Join 금지). 작업 스레드는 누름 유지 중에 정지되면 // 버튼 뗌을 SendInput 으로 보내는데, 그 입력은 UI 스레드의 마우스 후킹을 거쳐야 한다. // UI 스레드가 Join 으로 막혀 있으면 서로 기다리다 후킹이 시간 초과되고, // Windows 는 시간 초과된 저수준 후킹을 알림 없이 제거해 버린다. private void Stop() { running = false; worker = null; UpdateStatus(); } // 이번 실행이 아직 유효한지. 정지 직후 재시작하면 이전 작업 스레드가 잠깐 남아 있을 수 // 있는데, 세대(gen)가 다르면 곧바로 빠져나가게 해서 두 스레드가 겹쳐 클릭하지 않게 한다. private bool Alive(int gen) { return running && gen == generation; } private void Run(int gen, int interval, int hold, int jitter, long limit, int btnIndex, bool dbl, bool useFixed, int px, int py) { uint down, up; switch (btnIndex) { case 1: down = Native.MOUSEEVENTF_RIGHTDOWN; up = Native.MOUSEEVENTF_RIGHTUP; break; case 2: down = Native.MOUSEEVENTF_MIDDLEDOWN; up = Native.MOUSEEVENTF_MIDDLEUP; break; default: down = Native.MOUSEEVENTF_LEFTDOWN; up = Native.MOUSEEVENTF_LEFTUP; break; } long done = 0; while (Alive(gen)) { if (useFixed) Native.SetCursorPos(px, py); SendClick(gen, down, up, hold); if (dbl) { PreciseWait(gen, Math.Max(30, hold)); if (!Alive(gen)) break; SendClick(gen, down, up, hold); } if (!Alive(gen)) break; done++; Interlocked.Increment(ref clickCount); if (limit > 0 && done >= limit) break; double wait = interval; if (jitter > 0) { double delta = interval * (jitter / 100.0); lock (rnd) wait = interval + (rnd.NextDouble() * 2 - 1) * delta; if (wait < 1) wait = 1; } PreciseWait(gen, wait); } // 반복 횟수를 채워 스스로 끝난 경우에만 상태를 되돌린다 (재시작된 새 실행은 건드리지 않음) if (gen == generation) { running = false; try { BeginInvoke(new Action(UpdateStatus)); } catch { /* 폼이 이미 닫힌 경우 */ } } } // 버튼을 hold(ms) 동안 누르고 있다가 뗀다. // 게임은 매 프레임 입력 상태를 읽으므로, 누르고 떼는 게 한 프레임(약 16ms) 안에서 // 끝나면 클릭 자체를 놓친다. 그래서 누름과 뗌 사이에 실제로 시간을 둔다. // 정지되면 대기를 끊고 곧바로 떼므로 버튼이 눌린 채로 남지 않는다. private void SendClick(int gen, uint down, uint up, double hold) { SendButton(down); if (hold > 0) PreciseWait(gen, hold); SendButton(up); } private static void SendButton(uint flag) { Native.INPUT[] inputs = new Native.INPUT[1]; inputs[0].type = Native.INPUT_MOUSE; inputs[0].mi.dwFlags = flag; inputs[0].mi.dwExtraInfo = Native.SELF_TAG; Native.SendInput(1, inputs, Marshal.SizeOf(typeof(Native.INPUT))); } // Thread.Sleep 오차를 줄인 대기 (짧은 간격에서도 정확도 유지) private void PreciseWait(int gen, double ms) { Stopwatch sw = Stopwatch.StartNew(); while (true) { double remain = ms - sw.Elapsed.TotalMilliseconds; if (remain <= 0) return; if (!Alive(gen)) return; if (remain > 20) Thread.Sleep(10); else if (remain > 2) Thread.Sleep(1); else Thread.SpinWait(50); } } // ---- 설정 저장 / 불러오기 ---- private void SaveConfig() { try { StringBuilder sb = new StringBuilder(); sb.AppendLine("interval=" + (int)numInterval.Value); sb.AppendLine("hold=" + (int)numHold.Value); sb.AppendLine("jitter=" + (int)numJitter.Value); sb.AppendLine("button=" + cboButton.SelectedIndex); sb.AppendLine("clicktype=" + cboClickType.SelectedIndex); sb.AppendLine("repeat=" + (long)numRepeat.Value); sb.AppendLine("fixed=" + (rdoFixed.Checked ? 1 : 0)); sb.AppendLine("x=" + (int)numX.Value); sb.AppendLine("y=" + (int)numY.Value); sb.AppendLine("hotkey=" + (int)hotkey); sb.AppendLine("triggermouse=" + triggerMouse); sb.AppendLine("topmost=" + (chkTopMost.Checked ? 1 : 0)); File.WriteAllText(configPath, sb.ToString(), Encoding.UTF8); } catch { /* 저장 실패는 무시 */ } } private void LoadConfig() { try { if (!File.Exists(configPath)) return; foreach (string line in File.ReadAllLines(configPath)) { int i = line.IndexOf('='); if (i <= 0) continue; string key = line.Substring(0, i).Trim(); string val = line.Substring(i + 1).Trim(); long n; if (!long.TryParse(val, NumberStyles.Integer, CultureInfo.InvariantCulture, out n)) continue; switch (key) { case "interval": numInterval.Value = Clamp(n, numInterval); break; case "hold": numHold.Value = Clamp(n, numHold); break; case "jitter": numJitter.Value = Clamp(n, numJitter); break; case "button": if (n >= 0 && n < cboButton.Items.Count) cboButton.SelectedIndex = (int)n; break; case "clicktype": if (n >= 0 && n < cboClickType.Items.Count) cboClickType.SelectedIndex = (int)n; break; case "repeat": numRepeat.Value = Clamp(n, numRepeat); break; case "fixed": rdoFixed.Checked = n == 1; rdoCursor.Checked = n != 1; break; case "x": numX.Value = Clamp(n, numX); break; case "y": numY.Value = Clamp(n, numY); break; case "hotkey": if (n > 0 && n < 256) hotkey = (Keys)n; break; case "triggermouse": if (n >= 0 && n <= MB_X2) triggerMouse = (int)n; break; case "topmost": chkTopMost.Checked = n == 1; break; } } } catch { /* 손상된 설정 파일은 무시 */ } } private static decimal Clamp(long v, NumericUpDown nud) { decimal d = v; if (d < nud.Minimum) return nud.Minimum; if (d > nud.Maximum) return nud.Maximum; return d; } protected override void OnFormClosing(FormClosingEventArgs e) { running = false; SaveConfig(); UninstallHooks(); base.OnFormClosing(e); } } internal static class Program { [STAThread] private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } }