如何插入合成的鼠标事件到X11输入队列 [英] How to insert synthetic mouse events into X11 input queue

查看:222
本文介绍了如何插入合成的鼠标事件到X11输入队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了运行Linux / X11是连接到USB连接提供触摸事件的设备的嵌入式设备。这个装置不被识别为任何形式的标准指针/鼠标输入的。我想要做的是找到一种方法来注入鼠标事件到X11当外部设备报告的事件。

这样做会删除我的应用程序(使用GTK +用C语言编写)与GTK +通话假鼠标presses的需要。

如果可以做到这一点我的GTK +应用程序就不需要知道或关心设备产生的触摸事件。它只会出现在应用程序作为标准的鼠标事件。

任何人都知道如何去插入合成的鼠标事件到X11?

现在我正在做哪些工作,但不是最优以下。

 的GtkWidget * btnSpin; / *样品按钮* /gboolean按钮press_cb(无效* BTN);
gboolean buttonDe press_cb(无效* BTN);
/ *拨打这个电话设备库调用TouchEvent_cb()回调后
    和应用程序已经确定,如果有的话,按钮被触动    在这个例子中,我们假定btnSpin被感动了。    这个功能将在5毫秒,开始引起按钮做的过程
    正常的动画(在按钮,按钮出效果),然后发送实际
    button_clicked事件到按钮。
* /
g_timeout_add(5,(GSourceFunc)按钮press_cb,(无效*)btnSpin);
/ *这个回调上方g_timeout_add()函数之后解雇了5毫秒。
    它首先按钮状态设置为ACTIVE开始动画周期(pressed的样子)
    再后来250ms的调用buttonDe press_cb这将使该按钮看起来非pressed
    然后发送button_clicked事件。
* /
gboolean按钮press_cb(void *的BTN)
{    gtk_widget_set_state((GtkWidget的*)BTN,GTK_STATE_ACTIVE);
    g_timeout_add(250,(GSourceFunc)bu​​ttonDe press_cb,BTN);
    回报(FALSE);
}/ *设置回NORMAL(未pressed的样子)按钮状态
    并发送button_clicked事件使得用于在登记的信号处理程序
    按钮可以启动
* /
gboolean buttonDe press_cb(void *的BTN)
{    gtk_widget_set_state(BTN,GTK_STATE_NORMAL);
    gtk_button_clicked(GTK_BUTTON(BTN));    回报(FALSE);
}


解决方案

Linux的输入系统具有用户空间实现所谓uinput输入设备设施。您可以编写使用设备的回调库发送输入事件到内核中的后台程序。 X服务器(假设它使用了evdev输入模块),然后将处理这些就像任何其他的鼠标事件。

有一个名为库 libsuinput ,使这个很容易做到。它甚至还包括href=\"https://github.com/tuomasjjrasanen/libsuinput/blob/master/examples/mouse.c\">例如鼠标输入计划,你也许可以作为一种模式使用

I've got an embedded device running Linux/X11 that is connected to a device that provides touch events over a USB connection. This device is not recognized as any form of standard pointer/mouse input. What I'm trying to do is find a way to "inject" mouse events into X11 when the external device reports an event.

Doing so would remove the need for my application ( written in C using Gtk+ ) to fake mouse presses with Gtk+ calls.

If this can be done my Gtk+ application would not need to know or care about the device generating the touch events. It would just appear to the application as standard mouse events.

Anybody know how to go about inserting synthetic mouse events into X11?

Right now I'm doing the following which works, but isn't optimal.

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 );
}

解决方案

The Linux input system has a facility for user-space implementation of input devices called uinput. You can write a background program that uses your device's callback library to send input events to the kernel. The X server (assuming it is using the evdev input module) would then process these just as any other mouse event.

There's a library called libsuinput that makes this fairly easy to do. It even includes an example mouse input program that you can probably use as a model. However, since your device is a touch-based device it will probably use absolute axes (ABS_X, ABS_Y) instead of relative (REL_X, REL_Y).

这篇关于如何插入合成的鼠标事件到X11输入队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆