Re: keypressed() function

2006-12-28 Thread Ravi Teja

[EMAIL PROTECTED] wrote:
> I need a function (blocking or non-blocking) that tells me if a key has
> been pressed (even before it has been released etc.). Also, I would of
> course like to know _which_ key has been pressed.
>
> I know that this probably does not exist in the Python library already
> as a platform-independant abstraction (even though it probably could),
> but then I would at least like solutions that works on Windows and on
> Linux.

Hmm.. 2 questions on this today. On Windows PyHook will work. It
signals for both Key Up and Key Down events. However it is a Windows
only module making use of very platform specific API. I am not sure if
there is an equivalent for Linux.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keypressed() function

2006-12-28 Thread BJörn Lindqvist
> I know that this probably does not exist in the Python library already
> as a platform-independant abstraction (even though it probably could),
> but then I would at least like solutions that works on Windows and on
> Linux.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892

But it is blocking.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keypressed() function

2006-12-26 Thread Gabriel Genellina

At Tuesday 26/12/2006 10:25, [EMAIL PROTECTED] wrote:


I need a function (blocking or non-blocking) that tells me if a key has
been pressed (even before it has been released etc.). Also, I would of
course like to know _which_ key has been pressed.


On Windows you can listen to the messages WM_KEYDOWN/WM_KEYUP.
Or, for a specific key, you can use GetKeyState/GetAsyncKeyState. For 
the whole keyboard use GetKeyboardState.



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: keypressed() function

2006-12-26 Thread robert
[EMAIL PROTECTED] wrote:
> I need a function (blocking or non-blocking) that tells me if a key has
> been pressed (even before it has been released etc.). Also, I would of
> course like to know _which_ key has been pressed.
> 
> I know that this probably does not exist in the Python library already
> as a platform-independant abstraction (even though it probably could),
> but then I would at least like solutions that works on Windows and on
> Linux.
> 
> /David
> 

Its a terminal I/O function - not a platform function. E.g. On Win only in a 
rough console msvcrt.kbhit() does it. In PythonWin, IPython, Crust ... things 
are of course different. 
On regular Unix terminals you have the sys.stdin file:

sys.stdin.read(1)   #maybe in a thread and interthread-pass it to your main loop

or possibly trick with fcntl.fcntl(sys.stdin, fcntl.F_SETFL, 
os.O_NDELAY|os.O_NONBLOCK)

when nothing is on sys.stdin - you get immediately an IOError:

>>> sys.stdin.read(1)
Traceback (most recent call last):
  File "", line 1, in ?
IOError: [Errno 11] Resource temporarily unavailable


And see also other ioctl, termios, tty, cbreak, curses .. functions to get 
things early before \n  buffering depending on the terminal mode )


Robert
-- 
http://mail.python.org/mailman/listinfo/python-list


keypressed() function

2006-12-26 Thread [EMAIL PROTECTED]
I need a function (blocking or non-blocking) that tells me if a key has
been pressed (even before it has been released etc.). Also, I would of
course like to know _which_ key has been pressed.

I know that this probably does not exist in the Python library already
as a platform-independant abstraction (even though it probably could),
but then I would at least like solutions that works on Windows and on
Linux.

/David

-- 
http://mail.python.org/mailman/listinfo/python-list