How to detect that a key is being pressed, not HAS been pressed earlier!??

Gilles Lenfant glenfant at NOSPAM.bigfoot.com
Wed Jan 28 14:16:53 EST 2004


"Rune" <runed at stud.cs.uit.no> a écrit dans le message de
news:6ed33425.0401281103.61987e72 at posting.google.com...
> Hey
>
> I'm trying to build a gui application and need to know if the user is
> actually holding down the shift or ctrl key. That is, if the user
> currently is holding down the shift key. In pseudo code this will boil
> down to something like this:
>
> def test:
>   if user presses shift:
>     return SHIFT_IS_PRESSED
>   elif user presses ctrl:
>     return CTRL_IS_PRESSED
>   else
>     return false
>
> It's important to notice here that I'm not interested if the user has
> already pressed shift or ctrl. I'm only interested in knowing if he is
> currently holding down one of these keys. (I have looked into msvcrt
> and the like but have found no answer..) The function should also work
> in both windows and Linux.
>
> Any help is appriciated :)

You should have a look at the wxPython demo (wxKeyEvents section) that shows
how this is handled in a cross platform fashion.

Search for wxPython from www.sf.net

--
Gilles





More information about the Python-list mailing list