Skip to content

Instantly share code, notes, and snippets.

@seanh
Created August 28, 2010 21:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seanh/555602 to your computer and use it in GitHub Desktop.
Save seanh/555602 to your computer and use it in GitHub Desktop.
Keyboard shortcuts in PyGTK
self._window.connect("key-press-event",self._key_press_event)
def _key_press_event(self,widget,event):
keyval = event.keyval
keyval_name = gtk.gdk.keyval_name(keyval)
state = event.state
ctrl = (state & gtk.gdk.CONTROL_MASK)
if ctrl and keyval_name == 's':
self._notewindow.save()
elif ctrl and keyval_name == 'l':
self._searchwidget.grab_focus()
elif ctrl and keyval_name == 'j':
self._notestorewindow.next()
elif ctrl and keyval_name == 'k':
self._notestorewindow.prev()
elif keyval_name == "Escape":
self._searchwidget.clear()
else:
return False
return True
@JonasLoos
Copy link

thx

@brunoais
Copy link

brunoais commented Oct 1, 2019

ctrl = (state & gtk.gdk.CONTROL_MASK)
This seems to check if ctrl is included in the modifier keys pressed but it doesn't check if other modifiers were also pressed.
I.e. If Ctrl + Alt were pressed, along with s, the save window would also appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment