468,548 Members | 1,868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,548 developers. It's quick & easy.

Press any key to continue...

58
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...

Expand|Select|Wrap|Line Numbers
  1. >>> import msvcrt
  2. >>> msvcrt.getch()
  3. '\xff'
  4.  
Mar 19 '07 #1
9 25849
ghostdog74
511 Expert 256MB
a very basic implementation is like this:
Expand|Select|Wrap|Line Numbers
  1. import msvcrt
  2. while 1:
  3.     char = msvcrt.getch()
  4.     if char == chr(27):
  5.         break
  6.     print char,
  7.     if char == chr(13):
  8.         print
  9.  
Mar 19 '07 #2
shing
58
so how would u make it "any key"?

not just specifying exact ascii key values?
Mar 19 '07 #3
dshimer
136 Expert 100+
If all you want to do is pause something as simple as
Expand|Select|Wrap|Line Numbers
  1. def hit_continue(Prompt='Hit any key to continue'):
  2.     raw_input(Prompt)
  3.  
will work, and thats only if you want to make a function to do so. Otherwise just
Expand|Select|Wrap|Line Numbers
  1. raw_input('Hit any key to continue')
Mar 19 '07 #4
bartonc
6,596 Expert 4TB
If all you want to do is pause something as simple as
Expand|Select|Wrap|Line Numbers
  1. def hit_continue(Prompt='Hit any key to continue'):
  2.     raw_input(Prompt)
  3.  
will work, and thats only if you want to make a function to do so. Otherwise just
Expand|Select|Wrap|Line Numbers
  1. raw_input('Hit any key to continue')
Hey, D, doesn't that require input to be followed by the Enter key?
Mar 19 '07 #5
dshimer
136 Expert 100+
Yeah, my bad, I pulled it out of a location where I was hitting Enter to continue. Oops.
Mar 19 '07 #6
dshimer
136 Expert 100+
How about this. It seems to work, though the cursor drops to the next line.
Expand|Select|Wrap|Line Numbers
  1. import msvcrt
  2. char=0
  3. print 'hit a key'
  4. while not char:
  5.     char=msvcrt.getch()
Mar 19 '07 #7
bartonc
6,596 Expert 4TB
How about this. It seems to work, though the cursor drops to the next line.
Expand|Select|Wrap|Line Numbers
  1. import msvcrt
  2. char=0
  3. print 'hit a key'
  4. while not char:
  5.     char=msvcrt.getch()
That's the ticket! Now i just hope the OP stops in for the answer. Thanks, D.
Mar 19 '07 #8
shing
58
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...
Mar 21 '07 #9
ghostdog74
511 Expert 256MB
wat does getch do?

i cant understand the global module help file...
it gets a single character from input.
Mar 21 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by John Howard | last post: by
2 posts views Thread by Paul Johnston | last post: by
5 posts views Thread by junk mail | last post: by
6 posts views Thread by Bob Altman | last post: by
8 posts views Thread by Timur Ametov | last post: by
1 post views Thread by xinxin7311 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.