<p>Is there a good library to use for gathering user input in Linux from the mouse/keyboard/joystick that doesn't force you to create a visible window to do so?  SDL lets you get user input in a reasonable way, but seems to force you to create a window, which is troublesome if you have abstracted control so the control machine doesn't have to be the same as the render machine.  However, if the control and render machines are the same, this results in an ugly little SDL window on top of your display.</p>

<p><strong>Edit To Clarify</strong>:<br>
The renderer has an output window, in its normal use case, that window is full screen, except when they are both running on the same computer, just so it is possible to give the controller focus. There can actually be multiple renderers displaying a different view of the same data on different computers all controlled by the same controller, hence the total decoupling of the input from the output (Making taking advantage of the built in X11 client/server stuff for display less useable)  Also, multiple controller applications for one renderer is also possible.  Communication between the controllers and renderers is via sockets.</p>

[{'answer_id': 50220, 'author': 'Brian Gianforcaro', 'author_id': 3415, 'author_profile': 'https://Stackoverflow.com/users/3415', 'pm_score': 2, 'selected': False, 'text': '<p>For the mouse you can use <a href="http://www.linuxjournal.com/article/4600" rel="nofollow noreferrer">GPM</a>.</p>\n\n<p>I\'m not sure off the top of my head for keyboard or joystick.</p>\n\n<p>It probably wouldn\'t be too bad to read directly off there <code>/dev</code> files if need be. </p>\n\n<p>Hope it helps</p>\n'}, {'answer_id': 52266, 'author': 'Thomas Kammeyer', 'author_id': 4410, 'author_profile': 'https://Stackoverflow.com/users/4410', 'pm_score': 4, 'selected': True, 'text': '<p>OK, if you\'re under X11 and you want to get the kbd, you need to do a grab.\nIf you\'re not, my only good answer is ncurses from a terminal.</p>\n\n<p>Here\'s how you grab everything from the keyboard and release again:</p>\n\n<pre>\n/* Demo code, needs more error checking, compile\n * with "gcc nameofthisfile.c -lX11".\n\n/* weird formatting for markdown follows.  argh! */\n</pre>\n\n<p><code>#include &lt;X11/Xlib.h&gt;</code></p>\n\n<pre>\nint main(int argc, char **argv)\n{\n   Display *dpy;\n   XEvent ev;\n   char *s;\n   unsigned int kc;\n   int quit = 0;\n\n   if (NULL==(dpy=XOpenDisplay(NULL))) {\n      perror(argv[0]);\n      exit(1);\n   }\n\n   /*\n    * You might want to warp the pointer to somewhere that you know\n    * is not associated with anything that will drain events.\n    *  (void)XWarpPointer(dpy, None, DefaultRootWindow(dpy), 0, 0, 0, 0, x, y);\n    */\n\n   XGrabKeyboard(dpy, DefaultRootWindow(dpy),\n                 True, GrabModeAsync, GrabModeAsync, CurrentTime);\n\n   printf("KEYBOARD GRABBED!  Hit \'q\' to quit!\\n"\n          "If this job is killed or you get stuck, use Ctrl-Alt-F1\\n"\n          "to switch to a console (if possible) and run something that\\n"\n          "ungrabs the keyboard.\\n");\n\n\n   /* A very simple event loop: start at "man XEvent" for more info. */\n   /* Also see "apropos XGrab" for various ways to lock down access to\n    * certain types of info. coming out of or going into the server */\n   for (;!quit;) {\n      XNextEvent(dpy, &ev);\n      switch (ev.type) {\n         case KeyPress:\n            kc = ((XKeyPressedEvent*)&ev)->keycode;\n            s = XKeysymToString(XKeycodeToKeysym(dpy, kc, 0));\n            /* s is NULL or a static no-touchy return string. */\n            if (s) printf("KEY:%s\\n", s);\n            if (!strcmp(s, "q")) quit=~0;\n            break;\n         case Expose:\n               /* Often, it\'s a good idea to drain residual exposes to\n                * avoid visiting Blinky\'s Fun Club. */\n               while (XCheckTypedEvent(dpy, Expose, &ev)) /* empty body */ ;\n            break;\n         case ButtonPress:\n         case ButtonRelease:\n         case KeyRelease:\n         case MotionNotify:\n         case ConfigureNotify:\n         default:\n            break;\n      }\n   }\n\n   XUngrabKeyboard(dpy, CurrentTime);\n\n   if (XCloseDisplay(dpy)) {\n      perror(argv[0]);\n      exit(1);\n   }\n\n   return 0;\n}\n</pre>\n\n<p>Run this from a terminal and all kbd events should hit it.  I\'m testing it under Xorg\nbut it uses venerable, stable Xlib mechanisms.</p>\n\n<p>Hope this helps.</p>\n\n<p>BE CAREFUL with grabs under X.  When you\'re new to them, sometimes it\'s a good\nidea to start a time delay process that will ungrab the server when you\'re\ntesting code and let it sit and run and ungrab every couple of minutes.\nIt saves having to kill or switch away from the server to externally reset state.</p>\n\n<p>From here, I\'ll leave it to you to decide how to multiplex renderes.  Read\nthe XGrabKeyboard docs and XEvent docs to get started.\nIf you have small windows exposed at the screen corners, you could jam\nthe pointer into one corner to select a controller.  XWarpPointer can\nshove the pointer to one of them as well from code.</p>\n\n<p>One more point:  you can grab the pointer as well, and other resources.  If you had one controller running on the box in front of which you sit, you could use keyboard and mouse input to switch it between open sockets with different renderers.  You shouldn\'t need to resize the output window to less than full screen anymore with this approach, ever.  With more work, you could actually drop alpha-blended overlays on top using the SHAPE and COMPOSITE extensions to get a nice overlay feature in response to user input (which might count as gilding the lily).</p>\n'}]
['https://Stackoverflow.com/questions/50182', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5070/']