Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

hot keys in Console Application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexander - 17 Aug 2007 01:47 GMT
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?
Peter Duniho - 17 Aug 2007 02:38 GMT
> 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
Triple Threat - 24 Aug 2007 19:37 GMT
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
rossum - 24 Aug 2007 23:15 GMT
>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
[quoted text clipped - 8 lines]
>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
Hoop - 17 Aug 2007 13:39 GMT
On Aug 16, 7:47 pm, Alexander <Alexan...@discussions.microsoft.com>
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,
[quoted text clipped - 6 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.