CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    check for console input

    I was wondering how can I get the same effect of kbhit() from C/C++ in a C# console based application, i.e. do something (like stop the application) the moment a key was pressed?

    I have created this console based app, with this observer pattern: I have a clock subject with a timer that periodically updates its observers which display the time in the console. The thing is I want to stop it the moment I press a key, any key (and I don't want to use Ctrl+C ).
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: check for console input

    Take a look at the following...

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: check for console input

    It seems that the link is broken... Actually the whole site is down. I'll check it later.
    Last edited by cilu; February 13th, 2005 at 09:05 AM.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: check for console input

    Cilu, when you say that you've implemented an observer pattern - have you done this by hand ?

    Just to let you know you can write your own events and an event is effectively an inbuilt-observer pattern.

    If you're using events then ignore me. It's just in case you hadn't got to events in your C# investigations yet.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured