我有一个运行Linux/X11的嵌入式设备,连接着通过USB连接提供触摸事件的设备。该设备不被识别为任何形式的标准指针/鼠标输入设备。我尝试的是找到一种方法,在外部设备报告事件时可以“注入”鼠标事件到X11中。
这样做将消除我的应用程序(使用Gtk+编写)使用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 );
}