Linux input capture

Firstly, yes, I know about this issue , but I am looking for additional information about this. Actually, I have a pretty similar problem, as I need to be able to write input for mouse / keyboard / joystick, and I would also like to avoid SDL, if at all possible. I was more or less wondering if anyone knows where I can get decent primers for handling input from devices on Linux, perhaps even some tutorials. SDL is great for cross-platform input processing, but I'm not going to use anything else from the SDL, so I would like to completely eliminate it. Suggestions, comments and help are welcome. Thanks!

Edit for clarity:

The goal is to capture mouse movement, pressing / turning off the keyboard, mouse clicks and possibly controlling the joystick for the game.

+5
source share
5 answers

Using the link below, look at the void function kGUISystemX :: Loop (void)

This is my main loop for inputting keyboard and mouse input using X Windows on Linux.

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

Here is a snippet:

    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);
......
+5
source

If you know that your project will only run on Linux (not Windows or even one of the BSDs), you should study the Linux kernel input system. Download the kernel source and read Documentation/input/input.txt, in particular, the description of the system evdev.

( ) Xlib. , X-, . , , , , , , API .

+2
+1

, , , ( - )

If you are writing a GUI application (which runs in the X11 graphical environment), you can rely on graphical tool drivers (or raw X).

If you are writing a text-mode client, then readline or even ncurses may be good alternatives.

+1
source

You can get direct input from files in / dev / input. This is the easiest way to do this, and you do not need additional software.

-1
source

All Articles