c++ - 在 Linux 中捕获输入

标签 c++ linux

首先,是的,我知道 this question ,但我正在寻找更多信息。实际上,我有一个非常相似的问题,因为我需要能够捕获鼠标/键盘/操纵杆的输入,而且我也想尽可能避免使用 SDL。我或多或少想知道是否有人知道我可以从哪里获得一些关于在 Linux 中处理来自设备的输入的入门读物,甚至可能是一些教程。 SDL 非常适合跨平台输入处理,但我根本不会使用 SDL 中的任何其他内容,因此我想将其完全删除。建议、评论和帮助都值得赞赏。谢谢!

为清楚起见编辑:

重点是捕捉游戏的鼠标 Action 、键盘按下/释放、鼠标点击和潜在的操纵杆操作。

最佳答案

使用下面的链接查看函数 void kGUISystemX::Loop(void)

这是我在 Linux 上使用 X Windows 通过键盘和鼠标获取输入的主循环。

http://code.google.com/p/kgui/source/browse/trunk/kguilinux.cpp

这是一个片段:

    if(XPending(m_display))
    {
        XNextEvent(m_display, &m_e);
        switch(m_e.type)
        {
        case MotionNotify:
            m_mousex=m_e.xmotion.x;
            m_mousey=m_e.xmotion.y;
        break;
        case ButtonPress:
            switch(m_e.xbutton.button)
            {
            case Button1:
                m_mouseleft=true;
            break;
            case Button3:
                m_mouseright=true;
            break;
            case Button4:/* middle mouse wheel moved */
                m_mousewheel=1;
            break;
            case Button5:/* middle mouse wheel moved */
                m_mousewheel=-1;
            break;
            }
        break;
        case ButtonRelease:
            switch(m_e.xbutton.button)
            {
            case Button1:
                m_mouseleft=false;
            break;
            case Button3:
                m_mouseright=false;
            break;
            }
        break;
        case KeyPress:
        {
            XKeyEvent *ke;
            int ks;
            int key;

            ke=&m_e.xkey;
            kGUI::SetKeyShift((ke->state&ShiftMask)!=0);
            kGUI::SetKeyControl((ke->state&ControlMask)!=0);
            ks=XLookupKeysym(ke,(ke->state&ShiftMask)?1:0);
......

关于c++ - 在 Linux 中捕获输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/125806/

相关文章:

c++ - 如何在 C++ 中轻松切换算术?

linux - 如何在 Linux Ubuntu 上重置 yakuake 配置?

Linux 检索监视器名称

c++ - 安装旧版本的 gcc

javascript - 为什么 C++ CGI form_iterator 值没有进入 XMLHttpRequest 异步 Ajax 请求?

c++ - 唯一指针 : pointer being freed was not allocated when emplaced in list

C# 与 Mono 还是 C++? (运行Ubuntu)

linux - Pidof 找不到进程

c++ - 从dat文件读入数组

c++ - 在字典中查找单词模式,高性能