If you are using the key-press-event
signal callback, you can use the GdkEventKey structure. For example:
g_signal_connect (G_OBJECT (entry), "key-press-event",
G_CALLBACK (key_pressed), NULL);
/* ... */
key_pressed (GtkWidget *entry, GdkEventKey *event, gpointer data)
if (event->keyval == GDK_BackSpace)
else if ((event->keyval >= GDK_0 && event->keyval <= GDK_9) ||
(event->keyval >= GDK_KP_0 && event->keyval <= GDK_KP_9))
/* Insert the number (event->string) & then return TRUE */
In the code above, event->keyval is used to get the key that was entered. These values are available in gdk/gdkkeysyms.h. If it was a backspace (GDK_BackSpace), then handle that & return FALSE so GTK+ will handle the backspace.
If the key was a number of a number on the keypad, you should handle it & then return TRUE so GTK+ will take no further action. In any other case, return TRUE so that all other keys are ignored.
Hope this helps!