I had hoped that solaar would help, but it seems to only work for the Logitech wireless devices that use Logitech's proprietary scheme. I have Bluetooth keyboard (K760). I know it can be told to use the function keys (rather than the media keys) by default because I can do it on under OS X with software from Logitech. Just remapping the keys won't work as F1, F2, and F3 are special in that they switch which Bluetooth device I connect to and the keys are not sent to the OS.

  • What was your solution? I'm planning to get one for my Fedora GNU/Linux? – Ilia Rostovtsev Aug 13 '13 at 12:39

Hi I have the k760 keyboard an im also trying to find a way to do this. This seems to be a good place to start http://www.spinics.net/lists/linux-input/msg24280.html

He has managed to get it working for k810. if you can get the setpoint codes for the k760 you should be able to modify this code to make it work for k760 that is asuming that they are similar.

Update: I got it working !!! used the same procedure as describedd in the link.

#define HID_VENDOR_ID_LOGITECH          (__u32)0x046d
#define HID_DEVICE_ID_K810              (__s16)0xb316

const char k810_seq_fkeys_on[]  = {0x10, 0xff, 0x05, 0x14, 0x00, 0x00, 0x00};
const char k810_seq_fkeys_off[] = {0x10, 0xff, 0x05, 0x14, 0x01, 0x00, 0x00};
  • I am getting "error while getting info from device: Inappropriate ioctl for device" when I run ./k810_conf -d /sys/class/hidraw/hidraw2/device/uevent -f on. Are you sure those are all of the changes you made? Or am I using the wrong device? – Chas. Owens Jan 29 '14 at 12:54
  • Yeah you might need to try with another hidraw device. – Steven Jan 30 '14 at 12:51
  • The problem was that the device should have been /dev/hidraw2. However, now the problem is that it is saying write: 0 were written instead of 7. The write(1) call is not able to write any bytes to the device. I am emailing with the author of the utility, hopefully he will be able to shed some light on the problem. – Chas. Owens Jan 30 '14 at 14:00
  • I've seen that, but I think the functions key should be set as default now – Steven Jan 31 '14 at 22:07
  • The media keys are still the default. So it works for you even after the error message? – Chas. Owens Feb 3 '14 at 14:37
up vote 4 down vote accepted

It looks like the changes to the C code from the other answer do work (but off turns on the function keys, I had thought on would do that). I wanted to extend the code to auto-detect the keyboard for me and couldn't bear the thought of writing file searching code in C, so I ported the code to Perl 5:

#!/usr/bin/perl

use strict;
use warnings;

use constant HIDIOCGRAWINFO         => 2148026371;
use constant BUS_BLUETOOTH          =>          5;
use constant HID_VENDOR_ID_LOGITECH =>       1133;
use constant HID_DEVICE_ID_K760     =>     -19690;
use constant HID_DEVICE_ID_K760_ALT =>     -19688;
use constant HID_DEVICE_ID_K810     =>     -19687;

my %message = (
    HID_DEVICE_ID_K760() => {
        on   => (pack "C*", 0x10, 0xff, 0x05, 0x14, 0x00, 0x00, 0x00),
        off  => (pack "C*", 0x10, 0xff, 0x05, 0x14, 0x01, 0x00, 0x00),
    },
    HID_DEVICE_ID_K760_ALT() => {
        on   => (pack "C*", 0x10, 0xff, 0x05, 0x14, 0x00, 0x00, 0x00),
        off  => (pack "C*", 0x10, 0xff, 0x05, 0x14, 0x01, 0x00, 0x00),
    },
    HID_DEVICE_ID_K810() => {
        on   => (pack "C*", 0x10, 0xff, 0x06, 0x15, 0x00, 0x00, 0x00),
        off  => (pack "C*", 0x10, 0xff, 0x06, 0x15, 0x01, 0x00, 0x00),
    },
);

#die
#   "usage: $0 [on|off]\n",
#   "\ton  makes the media keys the default\n",
#   "\toff makes the function keys the default\n"
#unless @ARGV == 1 and my ($choice) = $ARGV[0] =~ /^(on|off)$/;
my ($choice) = @ARGV ? $ARGV[0] =~ /^(on|off)$/ : "off";

my $device;

# find the first device we can set the option on
# TODO: add a parameter to directly specify a device
# TODO: add a parameter to make it set all devices
FILE_SEARCH:
for my $file (</sys/class/hidraw/hidraw*/device/uevent>) {
    open my $fh, "<", $file or do {
        warn "could not open $file: $!\n";
        next;
    };

    while (<$fh>) {
        if (/HID_NAME=Logitech K(76|81)0/) {
            my ($hid_raw_name) = $file =~ m{(hidraw[^/]+)};
            $device = "/dev/$hid_raw_name";
            last FILE_SEARCH;
        }
    }
}

die "sorry, could not find a suported device on your machine\n" unless $device;

# re-exec with sudo if we can't open the device
unless (-r $device and -w $device) {
    # unless we are already root
    exec "sudo", $^X, $0, @ARGV unless $> == 0;
}

open my $dev, "+<", $device or die "could not open device $device: $!\n";

my $success = ioctl $dev, HIDIOCGRAWINFO, my $struct = "";

die "could not determine if $device is supported\n" unless $success;

my ($bus_type, $vendor, $product) = unpack "Lss", $struct;

die "detected device $device is not a Bluetooth device\n"
    unless $bus_type == BUS_BLUETOOTH;

die "detected device $device is not a Logitech product\n"
    unless $vendor == HID_VENDOR_ID_LOGITECH;

die "detected device $device is not a supported product\n"
    unless exists $message{$product};

syswrite $dev, $message{$product}{$choice};

close $dev;

Update: quick and dirty solution to the there being more than one device id for K760.

  • 1
    Answer above wont work on some K760 keyboards (at least at mine), so you have to change use constant HID_DEVICE_ID_K760 => -19690; to use constant HID_DEVICE_ID_K760 => -19688; – Alexey Hariton Nov 10 '15 at 9:41
  • @AlexeyHariton I have updated the code with the additional device id, please let me know if it works for you. – Chas. Owens Nov 11 '15 at 12:05

protected by Community Nov 11 '15 at 2:13

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.