Press any key to continue...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shing
    New Member
    • Mar 2007
    • 58

    Press any key to continue...

    I saw another thread about this, but it said this:

    import msvcrt
    msvcrt.getch()

    I can't quite seem to get that working on my python...

    Code:
    >>> import msvcrt
    >>> msvcrt.getch()
    '\xff'
    Last edited by shing; Mar 19 '07, 06:27 AM. Reason: sdf
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    a very basic implementation is like this:
    Code:
    import msvcrt
    while 1:
        char = msvcrt.getch()
        if char == chr(27):
            break
        print char,
        if char == chr(13):
            print

    Comment

    • shing
      New Member
      • Mar 2007
      • 58

      #3
      so how would u make it "any key"?

      not just specifying exact ascii key values?

      Comment

      • dshimer
        Recognized Expert New Member
        • Dec 2006
        • 136

        #4
        If all you want to do is pause something as simple as
        Code:
        def hit_continue(Prompt='Hit any key to continue'):
        	raw_input(Prompt)
        will work, and thats only if you want to make a function to do so. Otherwise just
        Code:
        raw_input('Hit any key to continue')

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by dshimer
          If all you want to do is pause something as simple as
          Code:
          def hit_continue(Prompt='Hit any key to continue'):
          	raw_input(Prompt)
          will work, and thats only if you want to make a function to do so. Otherwise just
          Code:
          raw_input('Hit any key to continue')
          Hey, D, doesn't that require input to be followed by the Enter key?

          Comment

          • dshimer
            Recognized Expert New Member
            • Dec 2006
            • 136

            #6
            Yeah, my bad, I pulled it out of a location where I was hitting Enter to continue. Oops.

            Comment

            • dshimer
              Recognized Expert New Member
              • Dec 2006
              • 136

              #7
              How about this. It seems to work, though the cursor drops to the next line.
              Code:
              import msvcrt
              char=0
              print 'hit a key'
              while not char:
              	char=msvcrt.getch()

              Comment

              • bartonc
                Recognized Expert Expert
                • Sep 2006
                • 6478

                #8
                Originally posted by dshimer
                How about this. It seems to work, though the cursor drops to the next line.
                Code:
                import msvcrt
                char=0
                print 'hit a key'
                while not char:
                	char=msvcrt.getch()
                That's the ticket! Now i just hope the OP stops in for the answer. Thanks, D.

                Comment

                • shing
                  New Member
                  • Mar 2007
                  • 58

                  #9
                  Originally posted by bartonc
                  That's the ticket! Now i just hope the OP stops in for the answer. Thanks, D.
                  wat does getch do?

                  i cant understand the global module help file...

                  Comment

                  • ghostdog74
                    Recognized Expert Contributor
                    • Apr 2006
                    • 511

                    #10
                    Originally posted by shing
                    wat does getch do?

                    i cant understand the global module help file...
                    it gets a single character from input.

                    Comment

                    Working...