Re: stopping a while True: with the keyboard



Benjamin <musiccomposition@xxxxxxxxx> writes:

On Sep 25, 8:19 pm, patrick <pured...@xxxxxxxxx> wrote:
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
.



Relevant Pages

  • Re: Recommended typefaces
    ... There are no decimal points on the typical computer keyboard. ... "Most operating systems" surely includes Microsoft Windows. ... point might prefer the Unicode "middle dot" character, ... of a minus sign. ...
    (alt.usage.english)
  • Re: Does something like this exist?
    ... > Synergy lets you easily share a single mouse and keyboard between ... > multiple computers with different operating systems, ...
    (borland.public.delphi.non-technical)
  • synergy on HPUX
    ... share a single mouse and keyboard between multiple computers ... with different operating systems without special hardware). ...
    (comp.sys.hp.hpux)
  • Re: Unable to use a PS/2 keyboard after a boot without it.
    ... as you booted the machine with a keyboard connected.. ... You can get a passive switch or a fancy electronic one. ... > With the passive one you must select the machine you want to boot. ... > passive one and switch between various operating systems and between AT and PS2 type ...
    (freebsd-stable)
  • Re: Keyboard keypress delay
    ... Working computer with no keyboard issues. ... I'm not sure whether it's an X11 problem, Linux problem, or KDE ... > Normally, a keypress causes the character to appear on screen immediately, ... > What is happening to me is that the first character isn't immediately ...
    (linux.redhat)