Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simple Win32 Console App question...

Simple Win32 Console App question...

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestionannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jc0dex
    wrote on last edited by
    #1

    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!

    P J 2 Replies Last reply
    0
    • J jc0dex

      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!

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      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!

      J 1 Reply Last reply
      0
      • P PJ Arends

        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!

        J Offline
        J Offline
        jc0dex
        wrote on last edited by
        #3

        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?

        P 1 Reply Last reply
        0
        • J jc0dex

          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?

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          • J jc0dex

            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!

            J Offline
            J Offline
            jc0dex
            wrote on last edited by
            #5

            I found that GetAsyncKeyState does exactly what I was needing. Thanks guys!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups