tags:

views:

309

answers:

3

I'm writing a TkInter application using Python 2.5 and I need to find out the status of the caps lock and shift keys (either true or false). I've searched all over the net but cant find a solution.

A: 

Lock and Shift event modifiers:

http://infohost.nmt.edu/tcc/help/pubs/tkinter/event-modifiers.html

vartec
A: 

I googled and got one.. I am not sure whether it works for you for all keys...

http://www.java2s.com/Code/Python/Event/KeyactionFunctionKeyALtControlShift.htm

lakshmanaraj
+1  A: 

Keyboard events in Tkinter can be tricky.

I suggest you have a look at the following, in order:

Here is a program that displays the value of the keycode and state event parameters. You can use this to experiment. Click in the window, then hit the keyboard.


from Tkinter import *
root = Tk()

def key(event):
    print "Keycode:", event.keycode, "State:", event.state

def callback(event):
    frame.focus_set()
    print "clicked at", event.x, event.y

frame = Frame(root, width=100, height=100)
frame.bind("", key)
frame.bind("", callback)
frame.pack()

root.mainloop()
codeape