1

I've been working on a system that runs as a console application. But I can't figure out how to create custom hotkeys for it.

CTRL - C is the Console.CancelKeyPress...

I'd like to add a custom hotkey like...

CTRL - S and have it run a function that I have in the code.

If anyone got any helpful tips or a basic layout for it please, feel free to reply.

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
Luciferus
  • 33
  • 1
  • 1
  • 6
  • Maybe you can read this post while you wait another answer :D http://stackoverflow.com/questions/3654787/global-hotkey-in-console-application – Krekkon Oct 19 '13 at 18:30
  • Console apps are not suitable for this, there's no mechanism beyond Console.ReadKey(). A global hotkey as shown in Krekkon's link is not equivalent to an application hotkey. Creating a GUI app in C# isn't very difficult, best way to move ahead. – Hans Passant Oct 19 '13 at 18:46
  • Hans Passant : I can't make the application a GUI based one because it'd take too much ram from the computer, application already gets upto 2gb ram when in full spin. It's a server system that has been setup. I need a custom hotkey such as the one i mentioned CTRL - S to save all information gathered on the server so it doesn't get lost when it crashes. – Luciferus Oct 20 '13 at 09:28

1 Answers1

0

Hi may be this can solve your problem. In my case I use such implementation for hotkey in my app. Class ConsoleKeyInfo is what you need

    ConsoleKeyInfo cki;
    do
    {
        cki = Console.ReadKey();
        if ((cki.Modifiers & ConsoleModifiers.Control) != 0 && cki.Key == ConsoleKey.Z)
        {
            Undo();
        }
        if ((cki.Modifiers & ConsoleModifiers.Control) != 0 && cki.Key == ConsoleKey.Y)
        {
            Redo();
        }
    } while (cki.Key != ConsoleKey.Escape);