public static void Record(Action action) { Console.WriteLine("Press " + Program.exitChar + " to quit."); KeyMouseFactory eventHookFactory = new KeyMouseFactory(Hook.GlobalEvents()); KeyboardWatcher keyboardWatcher = eventHookFactory.GetKeyboardWatcher().Disable(MacroEventType.KeyDown | MacroEventType.KeyUp).Enable(MacroEventType.KeyPress); Program._macroEvents = new List <MacroEvent>(); keyboardWatcher.OnKeyboardInput += (s, e) => { Program._macroEvents.Add(e); if (e.KeyMouseEventType == MacroEventType.KeyPress) { var keyEvent = (KeyPressEventArgs)e.EventArgs; Console.Write(string.Format("Key {0}\t\t{1}\n", keyEvent.KeyChar, e.KeyMouseEventType)); //var ch = Console.ReadKey(true).KeyChar; if (keyEvent.KeyChar == Program.exitChar) { keyboardWatcher.Stop(); eventHookFactory.Dispose(); Console.Clear(); Console.WriteLine("Record stopped"); Program.ConsoleLine(); action(); return; } } }; keyboardWatcher.Start(); }