#!/usr/bin/python
from gi.repository import Gtk, Gdk

def key_pressed(widget, event):
    print("key_pressed: {} {}".format(widget, event))

win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)

entry = Gtk.Entry()
entry.connect("key-press-event", key_pressed)

win.add(entry)
win.show_all()

#ev = Gdk.EventKey()
#print(type(ev))
## <class 'gi.overrides.Gdk.EventKey'>
#entry.emit("key-press-event", ev)
## TypeError: could not convert type EventKey to GdkEvent required for parameter 0

#ev = Gdk.EventKey(Gdk.EventType.KEY_PRESS)
## TypeError: function takes at most 0 arguments (1 given)

# As seen here for old PyGTK:
# http://stackoverflow.com/questions/2526589/forwarding-keypresses-in-gtk
#ev = Gdk.Event(Gdk.EventType.KEY_PRESS)
#ev.keyval = ord("A")
#ev.window = win.get_window()
#entry.emit("key-press-event", ev)
## no effect and window field ignored

# As seen here for old PyGTK:
# http://stackoverflow.com/questions/2526589/forwarding-keypresses-in-gtk
#ev = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
#ev.keyval = ord("A")
#ev.window = win.get_window()
#entry.emit("key-press-event", ev)
## no effect and window field ignored

#ev = Gdk.EventKey.new(Gdk.EventType.KEY_PRESS)
#print(type(ev))
## <class 'gi.overrides.Gdk.Event'> (not Gdk.EventKey)
#ev.keyval = ord("A")
#ev.window = win.get_window()
#entry.emit("key-press-event", ev)
## no effect and window field ignored

#ev = Gdk.Event(Gdk.EventType.KEY_PRESS)
#print(type(ev))
## <class 'gi.overrides.Gdk.Event'> (not Gdk.EventKey)
#ev.key = 1
## TypeError: argument 2: Must be Gdk.EventKey, not int

#ev = Gdk.Event(Gdk.EventType.KEY_PRESS)
#print(type(ev))
## <class 'gi.overrides.Gdk.Event'> (not Gdk.EventKey)
#ev.key = Gdk.EventKey()
## TypeError: cannot set a structure which has no well-defined ownership transfer rules

#ev = Gdk.EventKey.new(Gdk.EventType.KEY_PRESS)
#print(type(ev))
## <class 'gi.overrides.Gdk.Event'> (not Gdk.EventKey)
#ev.key = Gdk.EventKey()
## TypeError: cannot set a structure which has no well-defined ownership transfer rules


Gtk.main()
