using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; namespace ColorFinder { class Program { [DllImport("user32.dll")] static extern bool GetCursorPos(out Point lpPoint); [DllImport("user32.dll")] static extern void SetCursorPos(int x, int y); static void Main(string[] args) { bool isCapsLockOn = Console.CapsLock; // Check the initial state of the Caps Lock key if (isCapsLockOn) { Console.WriteLine("Caps Lock is ON. Press Caps Lock to enable/disable the color finder."); } else { Console.WriteLine("Caps Lock is OFF. Press Caps Lock to enable/disable the color finder."); } // Set up a global keyboard hook to detect the Caps Lock key press using (var hook = new KeyboardHook(Keys.CapsLock)) { hook.KeyPressed += (sender, e) => { isCapsLockOn = !isCapsLockOn; if (isCapsLockOn) { Console.WriteLine("Color finder is ON."); } else { Console.WriteLine("Color finder is OFF."); } }; // Start the keyboard hook hook.Start(); // Start the color finder loop while (true) { if (isCapsLockOn) { // Show the system color picker dialog to select a color var colorDialog = new ColorDialog(); colorDialog.ShowDialog(); // Get the selected color var color = colorDialog.Color; // Move the mouse cursor to the selected color SetCursorPos(color.R, color.G); } // Sleep for 100 milliseconds to reduce CPU usage System.Threading.Thread.Sleep(100); } } } } // Keyboard hook class to detect global key presses class KeyboardHook : IDisposable { private readonly KeyboardHooker hooker; private readonly Keys key; private bool disposed = false; public KeyboardHook(Keys key) { this.key = key; hooker = new KeyboardHooker(); } public void Start() { hooker.KeyPressed += Hooker_KeyPressed; hooker.Start(); } public void Stop() { hooker.KeyPressed -= Hooker_KeyPressed; hooker.Stop(); } private void Hooker_KeyPressed(object sender, KeyPressedEventArgs e) { if (e.Key == key) { KeyPressed?.Invoke(this, EventArgs.Empty); } } public event EventHandler KeyPressed; protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { Stop(); } disposed = true; } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } } // Keyboard hooker class to hook into low-level keyboard events class KeyboardHooker { private readonly LowLevelKeyboardProc proc; private IntPtr hookId = IntPtr.Zero; public KeyboardHooker() { proc = HookCallback; } public void Start() { using (ProcessModule module = Process.GetCurrentProcess().MainModule) {