This signal is emitted when a key has been pressed down.

This signal is emitted before any changes to the widget are made. For example, if you are using a GtkEntry, the signal will be emitted before the text of the entry is changed.

Useful event properties are:

Example 155. Using the key-press-event signal

$wnd = new GtkWindow();
$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));

//we want to receive key press events
$wnd->connect('key-press-event', 'onKeyPress');

//here we handle the key press events
function onKeyPress($widget, $event) {
    if ($event->state & Gdk::CONTROL_MASK && $event->keyval == Gdk::KEY_q) {
        //Press Ctrl+q, and the window will be closed
    } else if ($event->keyval == Gdk::KEY_F1) {
        //Press F1 to shwo a help text in the title
        $widget->set_title('Press Ctrl+Q to quit');


Callback function

bool callback(GtkWidget widget, GdkEvent event);