Jump to content

_getch, kbhit

- - - - -

  • Please log in to reply
5 replies to this topic

#1
irancplusplus

irancplusplus

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
Hi
what are the C# equivalents of the C++ functions: _getch and kbhit ?

_getch and kbhit can be used in Console Applications. kbhit returns true if a key is pressed and the queue is nonempty. _getch gets the character contained in the queue and empties it out of the queue.
I wrote this ebook! Will you translate it into English for free!?:confused: PM me!

#2
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
If you're working with Console applications then it would be:


Console.Read();

Console.ReadKey();

Console.ReadLine();

Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/

#3
irancplusplus

irancplusplus

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
ok this code:
char ch = Console.ReadKey().KeyChar;
works like _getch(). But how about kbhit?
kbhit returns true only if there are any characters in statndard input queue.

Edited by irancplusplus, 04 December 2011 - 10:04 AM.

I wrote this ebook! Will you translate it into English for free!?:confused: PM me!

#4
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
I found something like this on the web:

Quote

Sometimes people want a way to use a kbhit() like function in C# at the Console.

while( true )

{

  if( Console.KeyAvailable ) // since .NET 2.0

  {

    char c = Console.ReadKey().KeyChar ;

    Console.Write( c );

  }

}

Is it what you're looking for? If not please explain your question one more time :D
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/

#5
irancplusplus

irancplusplus

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
Exactly.
Thanks.
I wrote this ebook! Will you translate it into English for free!?:confused: PM me!

#6
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
Anytime.
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users