Alexander wrote:
Hi! I am new to C#. I read two C# books in the last two days which only
covered the basics. And now I am on my third day. The books were really bad,
because they did not cover windows applications, only ten to twenty pages how
to create forms.
So now you know why I want to have hotkeys in a CONSOLE Application.
Maybe I'm just thick, but I don't know why you want to have hotkeys in a
console application. I presume the first paragraph was supposed to
explain that, but I don't get it.
Is this
possible? I would be glad if you could give me some links in the msdn or just
the names of the functions needed.
If it's not possible how can I do it with minimum effort?
You should probably be more specific. Typically, a "hot key" is a
shortcut key that maps to some GUI command. Because a GUI application
is constantly in an event-handling loop (or at least, it should be :) )
it can always respond to user input.
A console application only responds to user input at certain times. If
you want to write a console application that can always respond to user
input, you should probably use a secondary thread to do whatever the
application is normally supposed to do, and have your main thread sit in
a loop accepting user input with ReadKey(). Then you can process the
keyboard input however you like.
Of course, you'll have to have some way for the threads to communicate
with each other, which introduces some complexity. The alternative is
to somehow have your main processing interrupt itself periodically to
check for input and respond to that. This is similar, but not
necessarily identical, to how the inter-thread communication would work
anyway, so to some extent that's "six of one, half-dozen of the other". :)
Pete