我有一个运行 Linux/X11 的嵌入式设备,它连接到通过 USB 连接提供触摸事件的设备。该设备不被识别为任何形式的标准指针/鼠标输入。我正在尝试做的是找到一种在外部设备报告事件时将鼠标事件“注入”到 X11 的方法。
这样做将消除我的应用程序(使用 Gtk+ 用 C 语言编写)通过 Gtk+ 调用伪造鼠标按下的需要。
如果可以做到这一点,我的 Gtk+ 应用程序就不需要知道或关心生成触摸事件的设备。它只会在应用程序中显示为标准鼠标事件。
有人知道如何将合成鼠标事件插入 X11 吗?
现在我正在做以下工作,但不是最佳的。
GtkWidget *btnSpin; /* sample button */
gboolean buttonPress_cb( void *btn );
gboolean buttonDePress_cb( void *btn );
/* make this call after the device library calls the TouchEvent_cb() callback
and the application has determined which, if any, button was touched
In this example we are assuming btnSpin was touched.
This function will, in 5ms, begin the process of causing the button to do it's
normal animation ( button in, button out effects ) and then send the actual
button_clicked event to the button.
*/
g_timeout_add(5, (GSourceFunc) buttonPress_cb, (void *)btnSpin);
/* this callback is fired 5ms after the g_timeout_add() function above.
It first sets the button state to ACTIVE to begin the animation cycle (pressed look)
And then 250ms later calls buttonDePress_cb which will make the button look un-pressed
and then send the button_clicked event.
*/
gboolean buttonPress_cb( void *btn )
{
gtk_widget_set_state((GtkWidget *)btn, GTK_STATE_ACTIVE);
g_timeout_add(250, (GSourceFunc) buttonDePress_cb, btn);
return( FALSE );
}
/* Sets button state back to NORMAL ( not pressed look )
and sends the button_clicked event so that the registered signal handler for the
button can be activated
*/
gboolean buttonDePress_cb( void *btn )
{
gtk_widget_set_state( btn, GTK_STATE_NORMAL);
gtk_button_clicked( GTK_BUTTON( btn ));
return( FALSE );
}