Re: Events and Signals



Ariel Fritz wrote:

Do you have some example about it?
The sample coming attached. Its very simple, read this to use/modify it for your needs:
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Events.html#gdk-event-put
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Keyboard-Handling.html
http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GTK-WIDGET-CAN-FOCUS-CAPS
http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-grab-focus

   Olexiy
/* compile with gcc -Wall `pkg-config --cflags --libs` event-put.c -o event-put

        This prog will set a characters [0-9] into GtkEntry with 1 sec period.

        NOTE:   there're many fields in GdkEventKey structure, this example shows the simpliest
                case.
*/

#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>


static gboolean event_put(GtkWidget *entry)
{
GdkEventKey event;

        memset(&event, 0, sizeof(event));       /* clear the structure */

        event.time = GDK_CURRENT_TIME;          /* current timestamp */
        event.type = GDK_KEY_PRESS;
        event.send_event = TRUE;                /* indicating that this event is synthetic */
        event.keyval = 0x30 + rand()%10;        /* generating character [0-9] */
        event.window = entry->window;           /* application window, will be non-zero after widget get 
realized */

        if (event.window)                       /* posting event if widget is realized */
                gdk_event_put((GdkEvent*)&event);

        return TRUE;
}

int main(int argc, char **argv)
{
GtkWidget *window;
GtkWidget *entry;

        gtk_init(&argc, &argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width(GTK_CONTAINER(window), 4);
        g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), 0);

        entry = gtk_entry_new();
        gtk_container_add(GTK_CONTAINER(window), entry);

        gtk_timeout_add(1000, (GtkFunction)event_put, window); /* setting callback with 1s period */

        gtk_widget_show_all(window);
        gtk_main();

        return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]