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 ESC Key

Simple ESC Key

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
5 Posts 3 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.
  • M Offline
    M Offline
    Michael101
    wrote on last edited by
    #1

    Hey everyone, I've got a C++ console application and it goes into a loop while that never ends except when the user presses the ESC key! Right now my loop is coded like this: while (!kbhit()) { code } I have to change the kbhit bit to make it so it only ends the loop when I press the ESC key! Thanks for your help in advance, I appreciate it! Michael

    N 1 Reply Last reply
    0
    • M Michael101

      Hey everyone, I've got a C++ console application and it goes into a loop while that never ends except when the user presses the ESC key! Right now my loop is coded like this: while (!kbhit()) { code } I have to change the kbhit bit to make it so it only ends the loop when I press the ESC key! Thanks for your help in advance, I appreciate it! Michael

      N Offline
      N Offline
      Nishad S
      wrote on last edited by
      #2

      while( 1 ) { if( kbhit()) { if( getch() == 27 ) break; } cout << "Hello "; }

      - NS -

      Z 1 Reply Last reply
      0
      • N Nishad S

        while( 1 ) { if( kbhit()) { if( getch() == 27 ) break; } cout << "Hello "; }

        - NS -

        Z Offline
        Z Offline
        zakkas2483
        wrote on last edited by
        #3

        it is mush simple if it is like that. while ( (ch = getch())!= 27 ) { /// loop statements } Thank You. hiren thakkar

        N 1 Reply Last reply
        0
        • Z zakkas2483

          it is mush simple if it is like that. while ( (ch = getch())!= 27 ) { /// loop statements } Thank You. hiren thakkar

          N Offline
          N Offline
          Nishad S
          wrote on last edited by
          #4

          It is wrong... The loop will be blocked, because getch will wait for key hit. The loop will be executed in each key strokes...

          - NS -

          Z 1 Reply Last reply
          0
          • N Nishad S

            It is wrong... The loop will be blocked, because getch will wait for key hit. The loop will be executed in each key strokes...

            - NS -

            Z Offline
            Z Offline
            zakkas2483
            wrote on last edited by
            #5

            yes , Your are right. Sorry i was missed interpreted that. Then your code is absolutely right

            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