static void Main(string[] args) { if (args.Length > 0) { var values = File.ReadAllText(args[0]); solveData(ColumnAndRowData.Parse(values)); } var id = HotKeyManager.RegisterHotKey(Keys.P, KeyModifiers.Control | KeyModifiers.Shift); HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed; Console.OutputEncoding = Encoding.Unicode; Console.WriteLine("Press Ctrl-Shift-P over the Pixelo window to solve it."); Console.WriteLine("Press q in this window to close it"); Console.WriteLine("Press o in this window to show the partial solutions overlapping (ON by default)"); Console.WriteLine("Press w in this window to have to press a key to see the next partial solution (ON by default)"); Console.WriteLine("Press c in this window to change the characters used to display the solutions"); Console.WriteLine("Press r in this window to replay the last solve"); while (true) { if (!Console.KeyAvailable) { Thread.Sleep(500); continue; } var key = Console.ReadKey(true).Key; if (key == ConsoleKey.Q) { break; } if (key == ConsoleKey.O) { _overlap = !_overlap; Console.WriteLine("Overlap mode for partial solutions is now " + (_overlap ? "ON" : "OFF")); } if (key == ConsoleKey.W) { _pressKeyToSeeSolutions = !_pressKeyToSeeSolutions; Console.WriteLine("Press a key to see next partial or total solution mode is now " + (_pressKeyToSeeSolutions ? "ON" : "OFF")); } if (key == ConsoleKey.C) { _charsIndex = (_charsIndex + 1) % _chars.Length; Console.WriteLine("The display charset is now " + string.Join(", ", _chars[_charsIndex])); } if (key == ConsoleKey.R && _data != null) { solveData(_data); } } HotKeyManager.UnregisterHotKey(id); }
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) { if (e.Modifiers != (KeyModifiers.Control | KeyModifiers.Shift) || e.Key != Keys.P) { return; } try { using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)) { Console.WriteLine("Getting screenshot"); using (Graphics g = Graphics.FromImage(bmpScreenCapture)) { g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, bmpScreenCapture.Size, CopyPixelOperation.SourceCopy); } SetFocus(); var parser = new ImageParser(); parser.Parse(bmpScreenCapture); Console.WriteLine(parser.Output); if (string.IsNullOrWhiteSpace(parser.Values)) { Console.WriteLine("Could not understand the screenshot"); return; } _data = ColumnAndRowData.Parse(parser.Values); solveData(_data); } } catch (Exception ex) { Console.WriteLine("There was an error in the program: " + ex.Message); } }