hot keys in Console Application

G

Guest

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. 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?
 
P

Peter Duniho

Alexander said:
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
 
H

Hoop

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. 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?

Hi Alexander,
Not sure what books you read but here is a link to a excellent free
one, pdf.
This covers the C# language. Also, a console app does not use windows
GUI( windows forms).

http://www.charlespetzold.com/dotnet/

Jeff
 
T

Triple Threat

So like my subject says, I have a windows form that has a side bar with some controls. The users are going to use the web browser for reading a script and it would be great if they didn't have to use the mouse to click the buttons but they could use hotkeys to hit the buttons. There are a couple problems I have encountered. First, I remember using VB 6.0 and being able to set the text of a button with an & and using the next character after it in the text as a shortcut. It looks like that would work here but it doesn't. Another issue I have is that while they are scrolling on the browser and maybe clicking buttons, I don't now how to send the window key strokes because the browser is getting "all of the attention" haha. How do I fix this?

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
R

rossum

So like my subject says, I have a windows form that has a side bar with some controls.
The users are going to use the web browser for reading a script and it would be great
if they didn't have to use the mouse to click the buttons but they could use hotkeys
to hit the buttons. There are a couple problems I have encountered. First, I remember
using VB 6.0 and being able to set the text of a button with an & and using the next
character after it in the text as a shortcut. It looks like that would work here but
it doesn't. Another issue I have is that while they are scrolling on the browser and
maybe clicking buttons, I don't now how to send the window key strokes because the
browser is getting "all of the attention" haha. How do I fix this?

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com

Use:

SendKeys.Send("^f");

to emulate a keystroke from code. SendKeys.Send() sends a keystroke
to the form that has focus.

rossum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top