如何将 Logitech K760 蓝牙键盘上的功能键设为默认键?

如何将 Logitech K760 蓝牙键盘上的功能键设为默认键?

我曾希望 solaar 能有所帮助,但它似乎只适用于使用 Logitech 专有方案的 Logitech 无线设备。我有蓝牙键盘 (K760)。我知道可以默认使用功能键(而不是媒体键),因为我可以在 OS X 下使用 Logitech 的软件进行操作。仅仅重新映射按键是行不通的,因为 F1、F2 和 F3 很特别,它们会切换我连接到哪个蓝牙设备,并且按键不会发送到操作系统。

答案1

嗨,我有 k760 键盘,我也在尝试找到一种方法来做到这一点。这似乎是一个很好的起点http://www.spinics.net/lists/linux-input/msg24280.html

他已设法使其在 k810 上工作。如果您可以获得 k760 的设定点代码,您应该能够修改此代码以使其在 k760 上工作,假设它们相似。

更新:我让它工作了!使用与链接中描述的相同的程序。

#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};

答案2

看起来对另一个答案中的 C 代码所做的更改确实有效(但关闭会打开功能键,我曾认为打开会这样做)。我想扩展代码以自动检测键盘,无法忍受用 C 编写文件搜索代码的想法,因此我将代码移植到 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;

更新:针对 K760 存在多个设备 ID 的快速而简单的解决方案。

相关内容