Simple Win32 Console App question...
-
Hey Guys .. I'm running a Win32 Console UDP Server/Client application. I want to run my server update function inside my main loop while also checking for key input. All I need to check for is if a single key has been pressed. The kicker is I need a way to continue on with the update without pausing for user input. When the user hits 't' for toggle it calls a function that closes the socket and reopens it as a server or client. Here's what I have now, but as I said I need something that doesn't wait for user input. Update() { char toggle; toggle = cin.get() if(toggle == 't') { ToggleMode(); } // get all the packets we can while(ReceiveData()); // Send all the data to the clients SendData(); return true; } Thanks in advance!
-
Hey Guys .. I'm running a Win32 Console UDP Server/Client application. I want to run my server update function inside my main loop while also checking for key input. All I need to check for is if a single key has been pressed. The kicker is I need a way to continue on with the update without pausing for user input. When the user hits 't' for toggle it calls a function that closes the socket and reopens it as a server or client. Here's what I have now, but as I said I need something that doesn't wait for user input. Update() { char toggle; toggle = cin.get() if(toggle == 't') { ToggleMode(); } // get all the packets we can while(ReceiveData()); // Send all the data to the clients SendData(); return true; } Thanks in advance!
-
Have a look at
_kbhit()
You may be right I may be crazy But it just may be a lunatic you’re looking for -- Billy Joel -- Within you lies the power for good - Use it!
-
Do I have to be using the CRT libraries for this? I tried including but when I do: if(_kbhit()) {ToggleMode()} It never gets into the true condition hen I press any key on the key board. Any help?
jc0dex wrote:
Do I have to be using the CRT libraries for this?
Yes.
_kbhit
is a C run-time function. Look it up in MSDN for some sample code.
You may be right I may be crazy But it just may be a lunatic you’re looking for -- Billy Joel -- Within you lies the power for good - Use it!
-
Hey Guys .. I'm running a Win32 Console UDP Server/Client application. I want to run my server update function inside my main loop while also checking for key input. All I need to check for is if a single key has been pressed. The kicker is I need a way to continue on with the update without pausing for user input. When the user hits 't' for toggle it calls a function that closes the socket and reopens it as a server or client. Here's what I have now, but as I said I need something that doesn't wait for user input. Update() { char toggle; toggle = cin.get() if(toggle == 't') { ToggleMode(); } // get all the packets we can while(ReceiveData()); // Send all the data to the clients SendData(); return true; } Thanks in advance!