473,385 Members | 1,766 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,385 software developers and data experts.

stopping a while True: with the keyboard

hi all,

i am looking for a way to break a while True: when pressing "s" on my
keyboard. how can i do this?

pat
Sep 26 '07 #1
5 2425
On Sep 25, 8:19 pm, patrick <pured...@11h11.comwrote:
hi all,

i am looking for a way to break a while True: when pressing "s" on my
keyboard. how can i do this?

pat
Ctrl-C

Sep 26 '07 #2
i don't want to quit my program only get out from a while True:
also i want to use only 1 key like s.

pat

Benjamin wrote:
On Sep 25, 8:19 pm, patrick <pured...@11h11.comwrote:
>hi all,

i am looking for a way to break a while True: when pressing "s" on my
keyboard. how can i do this?

pat

Ctrl-C

Sep 26 '07 #3
Hi,

I think you can use the 'curses' module to catch the keyboard event.
The name of the method is 'keyname()'. But I'm afraid curses is not
available on Windows Python, so you may have to be a bit more
imaginative. I just tried with Python 2.4 on Windows XP.

To leave the while loop, use the 'break' command.

Andy

Sep 26 '07 #4
Benjamin <mu**************@gmail.comwrites:
On Sep 25, 8:19 pm, patrick <pured...@11h11.comwrote:
hi all,

i am looking for a way to break a while True: when pressing "s" on my
keyboard. how can i do this?

pat

Ctrl-C
That's not a very helpful response, since it doesn't address the OP's
request.

Patrick, the operating system "interrupt current process" keyboard
signal will cause Python to raise a 'KeyboardInterrupt' exception,
which unless caught will propagate back to the top-level Python
process and exit the program with a traceback.

On most operating systems, you can send this signal to the current
foreground process with the key combination Ctrl+C. I think that's
what Benjamin's laconic response is implying.

As for "detect a specific keypress", there's no OS-independent way to
do that. You'll need to write code that depends on a particular way of
getting at keypresses that won't work on all operating systems.

--
\ "Those who write software only for pay should go hurt some |
`\ other field." -- Erik Naggum, in _gnu.misc.discuss_ |
_o__) |
Ben Finney
Sep 26 '07 #5
In message <ma**************************************@python.o rg>, patrick
wrote:
i am looking for a way to break a while True: when pressing "s" on my
keyboard. how can i do this?
<http://groups.google.co.nz/gr**********************@lust.ihug.co.nz>
Sep 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: ern | last post by:
I have a program that runs scripts. If the user types "script myScript.dat" the program will grab commands from the text file, verify correctness, and begin executing the script UNTIL... I need...
11
by: Steve | last post by:
I'm having a problem with my Thread usage and I think the general design of how I'm working with them. My UI class calls a method in another class that does a lot of work. That "worker" class...
4
by: bjm | last post by:
I am writing a program that will automate a series of application installations. I want to give the user the option of stopping the program's execution in between installations (for example, give...
6
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I have an application that is designed for using with a bar code scanner. I want the user to know that the scan was complete and the data was entered, so I am playing a system sound after data...
10
by: archana | last post by:
Hi all, I am having one windows service which is updating to database. On 'Onstop i want to wait till current updation complete. How will i do this? Because if i write some lengthy code on...
2
daniel aristidou
by: daniel aristidou | last post by:
Hi i wrote code to print records off a datagrid.the code works on all but one of my data grids. The problem is that loop continues without stopping, Causing the program to crash. The only diff...
2
by: Swan | last post by:
How can I restrict alt+tab and start menu from keyboard while program executing(VB)?I am posting what I tried-- form.frm Option Explicit Private Sub Form_Load() HookKeyboard End Sub...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.