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

static void
send_event (GdkEvent *event, guint keyval)
{
  GdkKeymapKey *keys = NULL;
  int n_keys;

  event->key.keyval = keyval;
  if (gdk_keymap_get_entries_for_keyval (NULL, keyval, &keys, &n_keys)) {
    event->key.hardware_keycode = keys->keycode;
    event->key.group = keys->group;
  } else {
    g_warning ("keyval 0x%X has no keys\n", keyval);
  }

  event->type = GDK_KEY_PRESS;
  gtk_main_do_event (event);
  event->type = GDK_KEY_RELEASE;
  gtk_main_do_event (event);
  g_free (keys);
}

static gboolean
push_events (gpointer data)
{
  GdkEvent event;

  event.key.window = gtk_window_get_focus (GTK_WINDOW (data))->window;
  event.key.send_event = FALSE;
  event.key.time = GDK_CURRENT_TIME;
  event.key.state = 0;
  event.key.length = 0;
  event.key.string = NULL;

  /* /us <tab> */
  send_event (&event, GDK_slash);
  send_event (&event, GDK_u);
  send_event (&event, GDK_s);
  send_event (&event, GDK_Tab);

  /* /usr/sh <tab> */
  send_event (&event, GDK_s);
  send_event (&event, GDK_h);
  send_event (&event, GDK_Tab);

  /* /usr/share/the <tab> */
  send_event (&event, GDK_t);
  send_event (&event, GDK_h);
  send_event (&event, GDK_e);
  send_event (&event, GDK_Tab);

  /* /usr/share/themes */
  return FALSE;
}

int
main (int argc, char **argv)
{
  GtkWidget *dialog;
  
  gtk_init (&argc, &argv);

  dialog = gtk_file_chooser_dialog_new (NULL, NULL, 
      GTK_FILE_CHOOSER_ACTION_OPEN, 
      GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, 
      NULL);

  gtk_widget_show_all (dialog);
  g_idle_add (push_events, dialog);
  gtk_dialog_run (GTK_DIALOG (dialog));

  return 0;
}

