Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16701 > unrolled thread
| Started by | Sergi Pasoev <s.pasoev@gmail.com> |
|---|---|
| First post | 2011-12-06 10:19 +0430 |
| Last post | 2011-12-06 07:38 -0800 |
| Articles | 9 — 7 participants |
Back to article view | Back to comp.lang.python
Single key press Sergi Pasoev <s.pasoev@gmail.com> - 2011-12-06 10:19 +0430
Re: Single key press 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-05 22:27 -0800
Re: Single key press 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-05 22:27 -0800
Re: Single key press alex23 <wuwei23@gmail.com> - 2011-12-06 00:39 -0800
Re: Single key press Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-06 08:48 +0000
Re: Single key press Hans Mulder <hansmu@xs4all.nl> - 2011-12-06 10:28 +0100
Re: Single key press Nobody <nobody@nowhere.com> - 2011-12-06 09:48 +0000
Re: Single key press Grant Edwards <invalid@invalid.invalid> - 2011-12-06 15:22 +0000
Re: Single key press 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-06 07:38 -0800
| From | Sergi Pasoev <s.pasoev@gmail.com> |
|---|---|
| Date | 2011-12-06 10:19 +0430 |
| Subject | Single key press |
| Message-ID | <mailman.3332.1323150597.27778.python-list@python.org> |
Hi. I wonder if it is realistic to get a single key press in Python without ncurses or any similar library. In single key press I mean something like j and k in Gnu less program, you press the key and and it is captured by the script without need to press enter afterwards
[toc] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-12-05 22:27 -0800 |
| Message-ID | <29114360.50.1323152868752.JavaMail.geo-discussion-forums@prcu10> |
| In reply to | #16701 |
On Tuesday, December 6, 2011 1:49:55 PM UTC+8, Sergi Pasoev wrote: > Hi. > > I wonder if it is realistic to get a single key press in Python > without ncurses or > any similar library. In single key press I mean something like j and k > in Gnu less > program, you press the key and and it is captured by the script without need to > press enter afterwards Sounds like the fast key searching for a list in the DOS application in the old days. This is easy in GUI of just tens of items, but for thousands of items such as in a directory listing, some API is really slow.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-12-05 22:27 -0800 |
| Message-ID | <mailman.3334.1323152877.27778.python-list@python.org> |
| In reply to | #16701 |
On Tuesday, December 6, 2011 1:49:55 PM UTC+8, Sergi Pasoev wrote: > Hi. > > I wonder if it is realistic to get a single key press in Python > without ncurses or > any similar library. In single key press I mean something like j and k > in Gnu less > program, you press the key and and it is captured by the script without need to > press enter afterwards Sounds like the fast key searching for a list in the DOS application in the old days. This is easy in GUI of just tens of items, but for thousands of items such as in a directory listing, some API is really slow.
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2011-12-06 00:39 -0800 |
| Message-ID | <90d8ede3-f42e-4342-91cf-cb671cd1b63b@c13g2000vbh.googlegroups.com> |
| In reply to | #16701 |
On Dec 6, 3:49 pm, Sergi Pasoev <s.pas...@gmail.com> wrote: > I wonder if it is realistic to get a single key press in Python > without ncurses or any similar library. It's possible using Tkinter in the standard library: http://www.daniweb.com/software-development/python/code/216830
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2011-12-06 08:48 +0000 |
| Message-ID | <4eddd6e7$0$11114$c3e8da3@news.astraweb.com> |
| In reply to | #16701 |
On Tue, 06 Dec 2011 10:19:55 +0430, Sergi Pasoev wrote: > Hi. > > I wonder if it is realistic to get a single key press in Python without > ncurses or > any similar library. In single key press I mean something like j and k > in Gnu less > program, you press the key and and it is captured by the script without > need to press enter afterwards Coincidentally, I was working on that exact function last night, so you inspired me to put it up on the Python cookbook. This version should work on any POSIX system such as Linux, as well as Windows. I don't know if it will work on Macintosh. http://code.activestate.com/recipes/577977-get-single-keypress/ -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Hans Mulder <hansmu@xs4all.nl> |
|---|---|
| Date | 2011-12-06 10:28 +0100 |
| Message-ID | <4edde040$0$6973$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #16709 |
On 6/12/11 09:48:39, Steven D'Aprano wrote: > On Tue, 06 Dec 2011 10:19:55 +0430, Sergi Pasoev wrote: > >> Hi. >> >> I wonder if it is realistic to get a single key press in Python without >> ncurses or >> any similar library. In single key press I mean something like j and k >> in Gnu less >> program, you press the key and and it is captured by the script without >> need to press enter afterwards > > > Coincidentally, I was working on that exact function last night, so you > inspired me to put it up on the Python cookbook. This version should work > on any POSIX system such as Linux, as well as Windows. I don't know if it > will work on Macintosh. > > http://code.activestate.com/recipes/577977-get-single-keypress/ It works fine on MacOS/X, but probably not on MacOS Classic. -- HansM
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-12-06 09:48 +0000 |
| Message-ID | <pan.2011.12.06.09.49.07.611000@nowhere.com> |
| In reply to | #16701 |
On Tue, 06 Dec 2011 10:19:55 +0430, Sergi Pasoev wrote: > I wonder if it is realistic to get a single key press in Python > without ncurses or any similar library. On Unix, you need to use termios.tcsetattr() to disable "canonical mode". Otherwise, the tty driver will only pass data up to the application when the user enters a newline or EOF. If you do this, you also need to handle SIGTSTP and SIGCONT, restoring the original terminal settings on SIGTSTP (typically generated by Ctrl-Z) and restoring the application's setting on SIGCONT.
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2011-12-06 15:22 +0000 |
| Message-ID | <jblbv9$sl8$1@reader1.panix.com> |
| In reply to | #16701 |
On 2011-12-06, Sergi Pasoev <s.pasoev@gmail.com> wrote:
> I wonder if it is realistic to get a single key press in Python
> without ncurses or
> any similar library.
Yes. Just put the tty associated with stdin in raw mode and make
single byte read() calls on it. Remember to restore the tty settings
when your program exits.
--
Grant Edwards grant.b.edwards Yow! World War III?
at No thanks!
gmail.com
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-12-06 07:38 -0800 |
| Message-ID | <29192698.206.1323185896052.JavaMail.geo-discussion-forums@prfs25> |
| In reply to | #16736 |
On Tuesday, December 6, 2011 11:22:18 PM UTC+8, Grant Edwards wrote: > On 2011-12-06, Sergi Pasoev <s.pa...@gmail.com> wrote: > > > I wonder if it is realistic to get a single key press in Python > > without ncurses or > > any similar library. > > Yes. Just put the tty associated with stdin in raw mode and make > single byte read() calls on it. Remember to restore the tty settings > when your program exits. > > -- > Grant Edwards grant.b.edwards Yow! World War III? > at No thanks! > gmail.com Cheers to virus scan software that has to scan fast and easily for all files under a drive. Easy clean up in APPS.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web