473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 27899
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

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

Similar topics

3
by: John Howard | last post by:
I'm trying to write a simple press any key routine, but am having some problems. Here is the routine: void PressAnyKey () { cout << "Press Any Key"; do{}while (!kbhit()); getch(); cout <<...
2
by: Paul Johnston | last post by:
I'm using VB.Net. I've tried using Console.Read() but it requires a line-terminator before it finishes (doesn't that mean it's functionally equivalent to ReadLine() -- why have it then?). I've...
5
by: junk mail | last post by:
My friend is trying to code a small c program where he wants to force the user to press enter and only enter to continue. Currently he is using getchar() with a loop but you can type any number...
6
by: Bob Altman | last post by:
Hi all, I have an unmanaged console app written in C++. I can't figure out how to get C++ to do the standard issue "press any key to continue" thing: cout << "Press any key to continue: ";...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a question about a script I'm trying to code and invoke when a button (btnSave) is pressed on the page. This script should only run when a textbox (txtAD) on the...
8
by: Timur Ametov | last post by:
Hallo everybody. I'm using Visual Studio 7 and hier is my question. How can i see in Outputwindow after my Programm ended the message "Press any key to continue". Is it possible? Now this window...
9
by: Susan Rice | last post by:
I'm running a simple win32 console application and I want to impliment a "Press any key to continue", so I print that prompt, and then what's the easiest way to impliment reading any key? Do I use...
4
by: kotoro | last post by:
I'm in an intro to computer programming course and just for the purposes of my test drivers and personal implementation, I would like to know if it is possible to force the program to wait for the...
1
by: xinxin7311 | last post by:
the program run:--in <input mesh> --out <output mesh> --maxDepth <octree depth> . press any key to continue.... but I press any key,the program will end,how can I do?
0
by: nstout | last post by:
writing a program in java System.out.print("Continue? (y/n): "); choice = sc.next(); System.out.println(); Then it displays "press any key to continue..." How do you stop this from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.