Web lists-archives.com

Re: XTestFakeKeyEvent GDK-equivalent




On Thu, 5 Jul 2018, Anarchean via gtk-list wrote:

I'm working into implementing a virtual remote keyboard/touch pad daemon for Linux, currently I'm dumping events into an uinput device, but that is giving me some trouble with my keyboard layout (which is brazillian, br-abnt2). I was looking for a way to this in X, found XTestFakeKeyEvent and was wondering if I could make it simpler and cross-platform using GDK3. I tried this attached code, but it doesn't do anything. I was wondering if someone has done this before and know what I'm doing wrong or if I should just give up doing with GDK.

The context is a little different, but the attached function works, given a pointers to an existing GtkWidget and GdkEvent.

Also, this is an extra, if I can't just fake key events, what should I use to map unicode chars into linux/input.h event key codes based on my keyboard layout on X? What about Wayland?

man xmodmap ?

--
Allin Cottrell
Department of Economics
Wake Forest University
static void manufacture_keystroke (GtkWidget *widget,
				   GdkEvent *orig,
				   guint uval)
{
    GdkKeymap *keymap = NULL;
    GdkKeymapKey *keys;
    gint n_keys;

#if GTK_MAJOR_VERSION >= 3 || defined(G_OS_WIN32)
    /* with GDK 3, we can't pass NULL for keymap below -- and neither
       (it appears) for GDK 2 on MS Windows
    */
    keymap = gdk_keymap_get_for_display(gdk_display_get_default());
#endif

    if (gdk_keymap_get_entries_for_keyval(keymap, uval, &keys, &n_keys)) {
	guint16 hardware_keycode;
	GdkEvent *event;

	hardware_keycode = keys[0].keycode;
	g_free(keys);

	event = gdk_event_new(GDK_KEY_PRESS);
	event->key.window = g_object_ref(gtk_widget_get_window(widget));
	event->key.hardware_keycode = hardware_keycode;
	event->key.keyval = gdk_unicode_to_keyval(uval);
	event->key.length = 1;
	event->key.send_event = FALSE;
	event->key.time = GDK_CURRENT_TIME;

#if GTK_MAJOR_VERSION >= 3
	/* we get warning spew if no device is attached */
	gdk_event_set_device(event, gdk_event_get_device(orig));
#endif

	gtk_main_do_event(event);
	gdk_event_free(event);
    }
}
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list