3

What is the event for the Windows key in Tkinter? I'm using Linux, but I would like answers for both Linux and Windows. If Mac has a similar key, feel free to let me know the binding for it. I imagine there are different events for the left and right windows keys.

The windows key doesn't seem to register in my program that is supposed to catch all key presses and print what they are to the screen. I haven't seen an answer in my searches online. I've seen references to Mod4 being associated with the Windows key, but that's not a proper Tkinter event (so says my error):

_tkinter.TclError: bad event type or keysym "Mod4"

E.g. the following code gets the above error.

textWidget.bind("<Mod4>", self.myFunction)
Brōtsyorfuzthrāx
  • 4,387
  • 4
  • 34
  • 56
  • 1
    Could you post the code where you attempt to create the binding? – Brionius Jun 17 '14 at 23:53
  • I don't have any code because I don't know an event name to use. If you're talking about Mod4 and thinking it should be binding successfully the Windows key (I don't know if it should be), I'll add that to my question. – Brōtsyorfuzthrāx Jun 19 '14 at 01:26
  • Related: https://stackoverflow.com/questions/72191674/modx-in-event-state-in-tkinter – Thingamabobs Nov 02 '22 at 08:37

2 Answers2

3

After some digging I found this: https://www.tcl.tk/man/tcl8.6/TkCmd/keysyms.htm These: <Win_L>, <Win_R>, appear to be the correct keys for Windows. Tested in Python 3.4 on Win7.

Von Pittman
  • 181
  • 1
  • 7
0

Okay, I found the answer. It was pretty simple, and I don't know why I couldn't find it on the Internet, anywhere.

The event is called Super_L (for the left Windows key on Linux). The right Windows key is Super_R. I don't know if these events work on Windows and Mac, though.

Anyway, the reason my event key-press finder didn't find it was because I had a script running at my computer start-up that defined the compose key as being the left windows key. So, it didn't register for some reason.

Brōtsyorfuzthrāx
  • 4,387
  • 4
  • 34
  • 56