Code Monkey home page Code Monkey logo

kbswitch's Introduction

NOTE: THE NEW (GITHUB) VERSION OF SOLAAR NOW SUPPORTS THIS KEYBOARD. INSTALL SOLAAR FROM SOURCE TO USE IT PROPERLY

THIS PROGRAM IS ALREADY REDUNDANT.


K780 Function Key Switcher

This is a small perl program for switching between media keys and function keys on the Logitech K780 keyboard.

Rather annoyingly this superb keyboard defaults to the function keys operating as media keys, and Logitech refuse to even acknowledge that Linux even exists!

Also Solaar doesn't (yet) support this keyboard any further than simply pairing it with the unified receiver.

So after some reverse engineering of the protocol this little program was born.

It simply sends the USB HID Output Report for switching between media keys and function keys, and nothing else. In the future it may be expanded to perform other functions.

Usage:

Select media keys:

kbswitch -m

Select function keys:

kbswitch -f

If you have multiple unifying receivers you can select it with a device path:

kbswitch -d 1-1.6 -f

You can also select the first device found using a VID and PID:

kbswitch -v 046d -p c52b -f

It defaults to the first device with the standard 046d:c52b VID/PID pair found.

You can also add the -n flag to send a destop notification through notify-send. This is useful if you bind the program to key combinations to switch between modes.


Historical notes and musings


A new cleaner system has been invented!

A simple udev rule:

SUBSYSTEM=="hidraw", KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52b", RUN+="/usr/sbin/keyswitch"

coupled with a tiny little script /usr/sbin/keyswitch:

#!/bin/bash

if [ "x$ACTION" = "xadd" ]; then
    printf '\x10\x02\x0c\x10\x00\x00\x00' > $DEVNAME
fi

is all that is needed!


Everything below this line is the old experimental system

Crude program to send the codes to switch the functionality of the K780 (and probably other Logitech keyboards too) function keys.

It's very much a work in progress, and is the result of my own reverse engineering of the protocol used.

Note: This breaks the reporting of information from the keyboard to Solaar. After using this program Solaar still reports the right number of devices paired, but it no longer lists the keyboard and its status.


Currently the method is very crude, and I need to find a better way of doing it.

The system is based around sending output reports to the keyboard. The ones used here are:

10 02 0c 1c 00 00 00

which switches to F key functionality, and

10 02 0c 1c 01 00 00

which switches to media key functionality.

The problem is I use HIDAPI to send the reports, and opening the device causes it to become unbound from the usbhid driver, making the keyboard and any other device on the same receiver inoperable. A new request to bind the device is then made through /sys/bus/usb/devices/usbhid/bind but it's far from a good system. A method needs to be found to send the output reports without having to unbind the device from the driver.

The ideal situation would be for Solaar to implement the ability to send these codes.

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.