Giter VIP home page Giter VIP logo

kfreestyle2d's Introduction

kfreestyle2d

Unofficial Kinesis Freestyle 2 Userspace Linux Driver

SECURITY NOTICE: This program should not run as root! Read the Install instructions for details on how to set the correct permissions on the device files that the driver opens so that it can do so with normal user permissions.

The Kinesis Freestyle 2 keyboard is a fantastic split keyboard for people who don't want RSI in their wrists. It has four multimedia keys on F8-F11 that do not work in Linux. This is a simple program that enables those keys. If you care how it works, keep reading. If not, skip to the Build instructions.

Origin

I spent a weekend digging into how this keyboard sent input for these multimedia keys. I documented the process in a series of blog posts:

Supported Systems

kfreestyle2d itself only depends on the Linux kernel. If you run Linux with uinput version 4 or later, you should be fine.

The automatic execution of kfreestyle2d currently depends on udev and systemd. If you run a system that uses a different init system or device manager, we'd love some help with automatic installation procedures on those systems.

How it works

The multimedia keys seem not to be understood properly by the hid-generic kernel module that usually interprets events from HID (Human Interface Devices). They are understood by the hidusb kernel module though, so you can read the raw HID file to get the stream of bytes coming from the USB device.

This program uses a special kernel interface called uinput that allows drivers for input devices to run as user programs. kfreestyle2d simply opens the raw byte stream from the keyboard's special function keys. When it reads a keypress, it translates the HID Usage ID of the key that it read into a keypress that the uinput system understands. This allows the kernel to interpret the keypress correctly and dispatch it to userspace programs like Xorg properly.

Build

make will create the binary kfreestyle2d in the current directory. If you want to try it without installing it, skip to the Manual Run section below.

Install

Please check the makefile before installing. You may wish to adjust the value of PREFIX or one of the other macros.

To properly install kfreestyle2d, you should be able to simply run sudo make install. This will:

  • Create a directory (default is /usr/local/share/kfreestyle2d) to store the executable and script.
  • Create some udev rules in /etc/udev/rules.d/99-kfreestyle2d.rules
  • Create a new systemd service file in /etc/systemd/system/kfreestyle2d.service

Once those things are done, the driver should run automatically when you plug in the keyboard and should stop when you unplug it. If you have any problems running this command, please open an issue.

Please note that the current setup only supports one Kinesis Freestyle 2. If you want to plug multiple Kinesis Freestyle 2 keyboards into the same computer, you'll need to customize the automatic execution accordingly.

Manual Run

This procedure will work to test whether the userspace driver is working without the udev and systemd automation in place. If you already followed the Install directions, you shouldn't need to do this.

First, ensure that the uinput kernel module is loaded with lsmod | grep uinput. If that does not return a line containing uinput, run sudo modprobe uinput to load the userspace input module into your kernel.

The driver expects to be given the path to an HID raw input device that corresponds to the special function keys of a Kinesis Freestyle 2.

To find the correct HID raw input device, unplug your keyboard and ls /dev/hidraw*. Then plug it in and ls /dev/hidraw*.

There should be two new /dev/hidrawX files the second time.

Try sudo head -c 1 /dev/hidrawA where A is the first new raw input file. Then type on your keyboard. If the command exits, it just read normal keyboard input from that file, which means that it is not the special function key raw input file. If the command does not exit, try typing one of the special keys (mute, volumedown, volumeup, calculator). Remember to press the function key before trying to use these. If the command exits when you type a special key, this is the file you're looking for.

To start the driver, run: ./kfreestyle2d /dev/hidrawX where X is the number of the raw input device for the special keys.

When the driver is running, it should create a new /dev/input/eventXX file, where XX is some number with 1-3 digits. You can run sudo evtest /dev/input/eventXX on that file to see the output generated by the driver when you press those keys.

If the driver isn't generating output, feel free to create an issue.

If it is, you should now be able to configure your programs to handle these keys using ordinary X or Wayland key configuration.

Contribute

Suggestions and PRs welcome!

kfreestyle2d's People

Contributors

arthurljones avatar chris-steinhoff avatar samiconductor avatar tatarianbarbarian avatar whereswaldon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kfreestyle2d's Issues

How to run?

Maybe I'm missing something, but I downloaded the ZIP, cd'd into it, and gave it a sudo make install. I restarted my computer, and can't tell that anything is different. I thought I needed to enable the systemd unit, but I got a message back from systemd saying that this isn't the case. How does one verify if the driver is installed and running?

Thanks for any help.

Ensure module insertion on boot in fedora and friends

Thanks to #7, the uinput group is created correctly at install time. So long as the uinput module is loaded when you boot your system, everything should be peachy. However, my F29 instance doesn't seem to load the module despite its presence in /etc/modules. I'm guessing that Fedora manages this a different way (dracut?), but it requires more research.

Thank you

Not an issue, but a thank you for creating and sharing this driver!
I just got a second hand Freestyle (not the v2, and a mac version actually) and was kind of bummed the media keys didn't work on Debian. I've forked your project and adapted the key mapping to work with this keyboard (apparently this older model uses some other key codes) and all of them work perfectly now (now to remap those silly copy-paste shortcut buttons somehow).

Would it be possible to swap the Alt and Command keys with this?

Thanks for creating this! I learned a lot reading your blog about this. I have the Mac version of this keyboard which has the bottom left keys as Ctrl-Alt-Command instead of the Ctrl-Win-Alt on the PC version of the keyboard. Could that order be changed to the Windows order by changing the mapping in k.c?

Thanks!

Support non-debian distros

Fedora and friends don't have the same semantics for adduser (it's a symlink to useradd). This means that installation fails on those systems. This should really be fixed, and is simply a matter of finding the right way to detect how to provision the user account.

Cannot build

Hello,
When I try to build the driver, I get several errors:

make
c99 -g -Wall -Wextra -pedantic   -c -o k.o k.c
k.c: In function ‘watch’:
k.c:45:25: error: storage size of ‘usetup’ isn’t known
     struct uinput_setup usetup;
                         ^
k.c:65:15: error: ‘UI_DEV_SETUP’ undeclared (first use in this function)
     ioctl(fd, UI_DEV_SETUP, &usetup);
               ^
k.c:65:15: note: each undeclared identifier is reported only once for each function it appears in
k.c:45:25: warning: unused variable ‘usetup’ [-Wunused-variable]
     struct uinput_setup usetup;
                         ^
<commande interne> : la recette pour la cible « k.o » a échouée
make: *** [k.o] Erreur 1

I have absolutely no knowledge of how make files work. Do you have an idea of what is actually going on?
Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.