473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to detect kbhit() in C#??

Hi,
How do you emulate a key board hit in C# without actually reading in
the character.

For instance I have the following code

Console.WriteLine("Press a enter to exit");
Console.ReadLine();

Instead of doing the above, I want to do something like the
following:

bool bExitFlagSet = false;
//The other thread may set the flag
//to true if certain conditions occur
SpawnAnotherThread();
Console.WriteLine("Press a enter to exit");
while(!kbhit() and (bExitFlagSet == false))
{
//be in the loop until a key press occurs
//or the bExitFlagSet is set to true from another
//thread
Sleep(5000);
}

How do I implement the kbhit() above. I am trying to find a way to
implement this in a console application.

Your help will be greatly appreciated.
Thanks
Lakshan

Lakshan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
1 8767
Lakshan wrote:
Hi,
How do you emulate a key board hit in C# without actually reading in
the character.

For instance I have the following code

Console.WriteLine("Press a enter to exit");
Console.ReadLine();

Instead of doing the above, I want to do something like the
following:

bool bExitFlagSet = false;
//The other thread may set the flag
//to true if certain conditions occur
SpawnAnotherThread();
Console.WriteLine("Press a enter to exit");
while(!kbhit() and (bExitFlagSet == false))
{
//be in the loop until a key press occurs
//or the bExitFlagSet is set to true from another
//thread
Sleep(5000);
}

How do I implement the kbhit() above. I am trying to find a way to
implement this in a console application.

Your help will be greatly appreciated.
Thanks
Lakshan

Lakshan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


One way to do that might be to hook keyboard messages (WH_KEYBOARD).
Although, I am not sure on how you would check which window was hit..
--
Girish Bharadwaj

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hans Georg Krauthaeuser | last post by:
Hey all, this is probably a FAQ, but I didn't found the answer... I use msvcrt.kbhit() to check for a user keyboard event on windows. But now, I would prefer to make the module independent...
7
by: DevarajA | last post by:
How can i know if there are characters in the standard input using only standard c++? I want to stop a loop when any key is pressed. -- Devaraja (Xdevaraja87^gmail^c0mX) Linux Registerd User...
17
by: hugo27 | last post by:
June 28, 2004 I'm interested in finding a way to test the keyboard buffer for MT/Not MT. Tried kbhit() in system.h but it didn't do what I thought it would from reading the literature. Samples:...
6
by: exquisitus | last post by:
Hi all, I'm porting a DOS application to run on Linux. I need to replace this function or use an equivalent. Anyone knows how or where I can get this function's equivalent (or maybe someones...
1
by: Carsten Orthbandt | last post by:
This code: ---snip--- #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <stdio.h> #include <tchar.h> #include <conio.h> int _tmain(int argc, _TCHAR*...
45
by: simnav | last post by:
In the following code something strange happens ! If I keep pressed any of ALT+Arrow, keys, they are extracted two times from buffer then getch seems to stop; if I release and press again ALT+arrow...
2
by: sk1988jun | last post by:
can anyone please tell me equivalent function in matlab for kbhit() which is a c fuction
1
by: palani12kumar | last post by:
Can anybody tell me, how the kbhit() works?
1
by: SpecialKay | last post by:
hey guys, i have a threaded program, i have loop that contunes until i get a kbhit() then, i playback repetively untill i get another kbhit(). EDIT: the first kbhit happens on a child thread of...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.