X4Daemon

X4Daemon is created to make it possible to use the extra keys on Microsoft’s Sidewinder X4 keyboard, which weren’t usable under linux until now. It takes control over the second interface of your X4 keyboard (first interface controls the “standard” keys, second interface controls the “special” keys like all media keys, calculator, S1 to S6,etc.) and passes all presses to uinput.

Under Windows you can record macros and switch between 3 banks on your X4 keyboard. I didn’t implement this feature because it is entirely done in software and my primary objective was to get the special keys working. I am also working on something for the 5 LEDs, it should be possible to use them for notifications or something like that. This will be released in some future version of X4Daemon.

Depending on your windowmanager you should be able to define keys somewhere, I use S1-S6 and Bank_Switch for switching between my virtual desktops in AwesomeWM, which is very nice. I didn’t test this in Gnome or KDE, but it should work fine. You can check if X4Daemon works correctly with xev. Mail me if you have problems getting it to work!.

I have no X6 keyboard, so if you have a X6 keyboard try it! You need to change the ProductID to the correct one (get it with lsusb) and then compile it. I don’t know if X6 has more keys or uses other keycodes, but if you mail me correct X6 keycodes I think I can implement them. But I don’t know how to get those keycodes, I didn’t need to find them for X4 because someone else did it already (see “Special thanks..”).

I made this package for Archlinux, I didn’t test it on any other distros. It should work fine, but you have to write your own init script I think. (I only wrote one for Archlinux.). If you got a working init script for your distro, mail it to me;-)

Special thanks go to tolga9009 for posting the keycodes on ubuntu forums and on libg15 forums. I have no idea how he got those keycodes… :D

You can download the latest source here (latest version is 0.4.4).
Here you can find the package in AUR.

md5sum: 1a8a52a713187cb1f0df08b906b2618d
sha256sum: 016f7ebfea90383b0a8e5218b9ca829b1fd715cd34a633c3a043fb0fe6fdf834

Howto compile it on other distros than Archlinux:

  1. I assume that you have build-essential (gcc,make,..), checkinstall, autoconf>=2.68 and libusb-1.0.0-dev installed. (package names depend on used distro)
  2. Download the sources
  3. tar -xvjf <archivename>
  4. autoconf (maybe not needed, only try if you have autoconf >= 2.68)
  5. ./configure
  6. make
  7. sudo checkinstall (or sudo make install <- not recommended)
  8. Start x4daemon (sudo x4daemon -w)
  9. For automatic start, just put x4daemon -w -D to /etc/rc.local (or create a init script for you distro ;))

Changelog:
2011/12/30 Version 0.1
– initial release

2011/12/31 Version 0.2
– added daemon mode (-D)
– added reinitalization when disconnecting device
– added waiting mode if disconnecting device (-w)
– added syslog for daemon mode
– added init script for arch linux
– added waiting for device at start when using -w

2012/01/07 Version 0.3
– added better checks to configure.ac
– added check for uniput module
– added auto load function for uinput module
– fixed some warnings while compiling (for some other distros)

2012/01/10 Version 0.4
– fixed help buffer error for -h
– added some more help/readme stuff (mainly XF86Keycodes)
– fixed pipes for some older shells (&> does not work on some sh)
– added waiting code after loading uinput module (for some distris like debian)

2012/01/14 Version 0.4.1
– changed version scheme
– fixed a bug for siduction, NULL for standard context in libusb_get_device_list does not work there

2012/01/14 Version 0.4.2
– fixed new version scheme problems…

2012/09/05 Version 0.4.3
– added systemd unit file

2012/09/05 Version 0.4.4
– fixed systemd unit file

Known Bugs:
– It works fine on virtualbox (stop X4Daemon on the host before trying!) until you want to end X4Daemon. X4Daemon then can’t release the interface correctly until you disconnect the usb device in virtualbox’s menu (X4Daemon will hang until you do this). This is not caused by X4Daemon (I think), it seem to be some problem with virtualbox’s usb drivers.

X4Daemon is reported/tested as working on following Distributions:
– Archlinux (of course)
– Linux Mint 11
– Debian Squeeze
– Siduction

Usage: x4daemon [OPTION]…

-d,–debug Activate debug mode.
-D, –daemon Activate daemon mode, alle messages go to syslog.
-h, –help Show this help page.
-r, –reset Reset device when starting (shouldn’t be necessary).
-v, –version Show version.
-w, –waiting Wait for device at start and if it disconnects.

 

Standard assignment of keys is:

Key: Keycode (input.h): Keycode: Keycode (XF86):
S1 KEY_PROG1 148 XF86Launch1
S2 KEY_PROG2 149 XF86Launch2
S3 KEY_WWW 150 XF86WWW
S4 KEY_MAIL 155 XF86Mail
S5 KEY_COMPUTER 157 XF86MyComputer
S6 KEY_PHONE 169 XF86Phone
Bank_Switch KEY_MEDIA 226 XF86AudioMedia
Record KEY_RECORD 167 XF86AudioRecord
Play_Pause KEY_PLAYPAUSE 164 XF86AudioPlay
Previous KEY_PREVIOUSSONG 165 XF86AudioPrev
Next KEY_NEXTSONG 163 XF86AudioNext
Mute KEY_MUTE 114 XF86AudioMute
VolumeUp KEY_VOLUMEUP 115 XF86AudioRaiseVolume
VolumeDown KEY_VOLUMEDOWN 114 XF86AudioLowerVolume
Calculator KEY_CALC 140 XF86Calculator

 

You can change the keys in source code, see keys[] array.
(I just used some unused keycodes for the special keys.)
Mute,Prev,Next,PlayPause,VolDown, VolUP and Calc use the same keycodes as before.
See /usr/include/linux/input.h for more information.
It is not possible to switch banks or to record macros.
If you find any bugs or if you want to tell me something click here.

X4Daemon comes with absolutely no warranty.
It is licensed under the GPL (General Public License), version 2 or later.
Details should be in the src package or at http://www.gnu.org/licenses/licenses.

Older versions of X4Daemon:
X4Daemon 0.4.3
md5sum: b9ed72ed0a3f04723e8c10dfd7745f7f
sha256sum: 5ae8f6f8207a4267d3cc471128bfbe0ec762b57123051aeb4392c7a2aefe5463

X4Daemon 0.4.2
md5sum: b2964ce1d21f3031ccc4cfa449c0f05d
sha256sum: d65058b5a76cb7161010d097af3de9064230f179ac9fddfb7ec4d13664c047f1

X4Daemon 0.4.1
md5sum: c749935260f9ad91b2305c4fe58d8111
sha256sum: d8d77531f343e68cad5e9b11008953b7b14f82c8157828985d0286aa3f9032be

X4Daemon 0.4
md5sum: 23c77844940fe9f1bb351de7fe701cb1
sha256sum: 508277ea7bb7d227dc16eff98402eddff96fe3cedc63a84d5145db70d4ade7e2

X4Daemon 0.3
md5sum: e1cc8aa21ad17eb9475af2d2043c1839
sha256sum: fa21d8bf4074972a78bc4c2154fc0fa93dcc2667c9af3fe60a4cc5d802ba0d59

X4Daemon 0.2
md5sum: f5ba0722429911fb3cb669e56f98fe52
sha256sum: c9e4741a1432d4ddda2ca45a5f1b323d86c244909cea83e05fd9f28522461016

Comments (21)

  1. 19:14, January 10, 2012Timsche  / Reply

    Hi,

    ./x4daemon -w
    Starting…!
    uinput 6400 2
    Memory Access Error

    I started it as root and installed like you described it for other distros.
    I’m on Debian.

  2. 21:28, January 10, 2012Andreas  / Reply

    Which Debian do you use? Squeeze?

    I try that later ;)

  3. 02:19, January 11, 2012Andreas  / Reply

    I tried on debian squeeze, works fine. I also fixed some other problems for debian, please try again with 0.4. If you still got errors please post debug output (“x4daemon -w -d”).

  4. 20:06, January 12, 2012Timsche  / Reply

    ./x4daemon -w -d
    Starting…!
    Debug: Uinput module already loaded.
    Debug: Uinput initalized…
    Debug: Waiting for device…
    Debug: Trying to reinitalize the device…
    Speicherzugriffsfehler

    Ist immer noch wie vorher – benutze Debian Siduction was aber kein Problem darstellen sollte… Hoffe du kannst was mit den Debugausgaben anfangen, wäre echt nice das Teil zum Laufen zu kriegen.

  5. 16:38, January 14, 2012Andreas  / Reply

    Liegt irgendwie an Siduction selbst, er mag da den standard context in libusb_get_device_list nicht, geht aber nun in 0.4.1 ;)

  6. 17:59, January 14, 2012Timsche  / Reply

    $ make
    make all-am
    make[1]: Entering directory `/home/tim/Downloads/x4daemon-0.4.1′
    gcc -DHAVE_CONFIG_H -I. -g -O2 -MT x4daemon.o -MD -MP -MF .deps/x4daemon.Tpo -c -o x4daemon.o `test -f ‘src/x4daemon.c’ || echo ‘./’`src/x4daemon.c
    src/x4daemon.c: In function ‘interpret_args’:
    src/x4daemon.c:344:25: error: too many decimal points in number
    src/x4daemon.c:352:50: error: too many decimal points in number
    make[1]: *** [x4daemon.o] Fehler 1
    make[1]: Leaving directory `/home/tim/Downloads/x4daemon-0.4.1′
    make: *** [all] Fehler 2

    Habe das #define version in Zeile 33 auf 0.41 gesetzt statt 0.4.1 – das müsstest vll noch anpassen und ansonsten laufen die S-Tasten jetzt soweit – danke dir =)

  7. 00:05, January 15, 2012Andreas  / Reply

    Ups.. vllt. sollte ich es nachdem ich die Version geändert hab auch nochmal testen :D

  8. 09:02, January 27, 2012no  / Reply

    Hi Andreas,

    Klasse Arbeit, danke dafür.
    Der Daemon in Version 0.42 läuft hier auf einem debian sid mit vanilla kernel ohne Probleme

    • 17:38, January 29, 2012Andreas  / Reply

      Danke, freut mich zu hören!

  9. 02:13, May 10, 2012Bill  / Reply

    Is there any chance that this will work with the older X6 Sidewinder?
    The X6 just has the ability to use the numpad as a macro-pad (keys S13 to S30) and allows S1-S6 to become S7 to S12 by the use of a small button on the keyboard.

    Thanks in advance

  10. 12:20, May 11, 2012Andreas  / Reply

    Hi Bill, sry. I have no X6 here and I don’t know the exact keycodes or anything for it. If you captured the codes it shouldn’t be that hard to get it work. You basically have to add the keycodes and the usbid. (unless ms did not use a complete different system for it)

  11. 16:17, May 12, 2012Binsh  / Reply

    Thanks!

    Works like a charm in Ubuntu 12.04 :)

  12. 22:06, May 21, 2012Thom  / Reply

    I’m using the x4daemon on Arch but every time after suspending I have to restart the daemon. Is there any way that this can survive a suspend?

  13. 18:09, November 18, 2012Pat  / Reply

    If I want to make S6 the middle mouse button click, what value would I change in input.h? If I change it, can I still use the middle mouse button on the actual mouse? Thanks

  14. 09:17, September 15, 2013keil  / Reply

    Geht ohne probleme unter Mint 15 64bit

    Works on Mint 15 64bit

    Thanks

  15. 19:56, November 19, 2013tolga9009  / Reply

    I’ve got a solution for the profile switching: http://ubuntuforums.org/showthread.php?t=1543370&page=4. Currently working on advanced stuff, like Macro’s etc., I’ll do some clean ups after that.

  16. 17:19, November 29, 2013Jan  / Reply

    Thanks
    Works on OpenSuse 13.1 64bit

  17. 05:32, January 4, 2014Shane  / Reply

    Thanks for this – it truely is great. I wanted to inform you of something I have noticed though. Before activating the daemon my XF86AudioPlay, Next, Prev all work great and I can assign keybindings in awesome that use multiple keys such as mod4 + Control + XF86AudioPlay and md4 + Shift + XF86AudioPlay to do different functions. However when I enable the daemon I lose the ability to use multiple keys for the keybinding on any of the keys the daemon controls. This is not a huge issue but would be fantastic to have again.

  18. 00:35, January 12, 2014tolga9009  / Reply

    Hi Shane,

    x4daemon is handling media control buttons, eventhough they’re working without it (which I think is a flaw in x4daemon’s current version. Why fix something, that isn’t broken?). You would need to modify the source and recompile it. Search for “int key[15]” and set it to “int key[8]”. In the array, delete “KEY_PLAYPAUSE, KEY_PREVIOUSSONG, KEY_NEXTSONG, KEY_MUTE, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_CALC”. Also delete the “else if” statements of these keys and anything else, that refers to these keys. Try to compile it.

    If this is too complicated for you, you could also try the kernel module drivers (as long as you’re at least on Linux 3.12):
    https://github.com/tolga9009/hid-sidewinder-x4. They also support the LEDs and profile switching. Instructions here: http://ubuntuforums.org/showthread.php?t=1543370&page=5. You’d need to figure out, how to load the kernel module drivers at boot time.

  19. 13:33, May 18, 2014Andreas  / Reply

    hi tolga9009,
    Just a quick answer for the media control buttons: It is in my opinion impossible to get control over the S1-S6 (etc.) buttons without taking the control of media control buttons. Internal the X4 is splitted in two keyboard usb devices. If you want to capture the S1-S6 buttons, you also need to take care of the media control buttons. Why no key combos work in awesome is another question, this should definetly work.

    But I think you should know this .. as you point out on your github page “I know absolutely everything about the Sidewinder X4″ ;)

  20. 02:16, June 9, 2014tolga9009  / Reply

    Hehe Andreas,

    never say never ^_^. Well, I have found a way to take care of S1 – S6 keys without touching the media keys. The keyword is hidraw. In your implementation, you have used libusb, which detaches the interface #1 (S1-S6, media keys, etc.) from kernel and you need to take care of these media keys. S1-S6 and media keys might be on the same interface, but if you don’t detach it from the kernel, the media keys are working.

    In sidewinderd, I’m using hidraw instead of libusb, which gives me access from userland to listen to hid events and act to them accordingly. S1-S6, Bank Switch and Record key send out correct hid events, so no problems there. There is no detaching from kernel driver, media keys function as we’re used to – and we don’t need to exclusively take care about them ;).

    It looks veeery promising so far and major parts of the code are already working (S1 – S30 keys, Profile LEDs, Bank Switch, Record LEDs, Macro Player using Microsoft’s XML format, Media keys out-of-the-box and Macropad Toggle on X6). There is still lots and lots of work to be done (like daemon mode and macro recording for example) though :(. You still might give it a try, I’m open for any suggestions: https://github.com/tolga9009/sidewinderd

    Greetings,
    Tolga

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>