Keybindings: Recognizing Control, Alt, etc on different platforms

Fredrik Lundh fredrik at pythonware.com
Fri Sep 24 05:06:35 EDT 1999


Egeland <egelando at online.no> wrote:
> Hi all. My app uses the "<Key>" binding, and I must know in the callback
> procedure if thats a
> Control-k or plain k coming in. On Linux, say, I can use the clause
> 
> if event.keysym=="k" and event.state==4:    # Control-k, not just 'k'
>     # do something
> 
> but that wont work on win32. Is there some platform independent way of
> recognizing modifications like Control, Alt, and Shift ?

state is a bitmap; try changing your test to:

> if event.keysym=="k" and event.state & 4:    # Control-k, not just 'k'
>     # do something

(unless you want to tell your customers to avoid
using numlock, of course ;-)

</F>





More information about the Python-list mailing list