views:

152

answers:

1

Is there any way to detect which keys are currently pressed using Tkinter? I don't want to have to use extra libraries if possible. I can already detect when keys are pressed, but I want to be able to check at any time what keys are pressed down at the moment.

+2  A: 

I think you need to keep track of events about keys getting pressed and released (maintaining your own set of "currently pressed" keys) -- I believe Tk doesn't keep track of that for you (and Tkinter really adds little on top of Tk, it's mostly a direct interface to it).

Alex Martelli
Correct. Tk gives no way to know which keys are pressed. It's fairly trivial to make a single binding to <Any-KeyPress> and <Any-KeyRelease> to capture keys. This won't help if you want to detect keys that were pressed when the app first starts up.
Bryan Oakley