「キーボードバックライト」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎Asus: 削除)
(→‎全メーカー共通: 英語版より記事を追加)
3行目: 3行目:
 
キーボードのバックライトの輝度レベルを制御するには、さまざまな方法があります。
 
キーボードのバックライトの輝度レベルを制御するには、さまざまな方法があります。
 
== 全メーカー共通 ==
 
== 全メーカー共通 ==
  +
  +
There are a variety ways to manage the brightness level and different helpers tools to accomplish this, such as {{Pkg|brightnessctl}} or {{Pkg|light}}.
  +
  +
The {{ic|sys}} pseudo-file system exposes an interface to the keyboard backlight. The current brightness level can be get by reading {{ic|/sys/class/leds/tpacpi::kbd_backlight/brightness}}. For example to get the maximum brightness level:
  +
  +
$ cat /sys/class/leds/tpacpi::kbd_backlight/max_brightness
  +
  +
To set the brightness to 1:
  +
  +
# echo 1 > /sys/class/leds/tpacpi::kbd_backlight/brightness
  +
  +
When using {{ic|brightnessctl}} you can get a list of available brightness controls with {{ic|brightnessctl --list}}, then to show the kbd backlight information:
  +
  +
$ brightnessctl --device='tpacpi::kbd_backlight' info
  +
  +
This will show the absolute and relative current value and the maximum absolute value. To set a different value:
  +
  +
$ brightnessctl --device='tpacpi::kbd_backlight' set 1
  +
  +
=== xset ===
  +
  +
Some keyboard manufactores are not recognized by {{Pkg|brightnessctl}} or {{Pkg|light}}, but you can use {{Pkg|xorg-xset}} to control its lights if you are running Xorg.
  +
  +
The first parameter {{ic|led}} turns on the led, and {{ic|-led}} turns it off, the {{ic|NUMBER}} parameters accepts integers for 1 to 32 (each number corresponds to a led in you system, keyboards seem to generally be number 3), or 'on' and 'off' (on will turn ALL lights on, and off will turn ALL lights off).
  +
  +
To turn on the lights:
  +
  +
$ xset led NUMBER
  +
  +
To turn off the lights:
  +
  +
$ xset -led NUMBER
  +
  +
=== D-Bus ===
 
[[D-Bus]] インタフェース経由でコンピュータのキーボードのバックライトを制御することができます。D-Bus を使用する利点は、デバイスファイルへの変更が必要なく、全てのメーカーで使えることです。
 
[[D-Bus]] インタフェース経由でコンピュータのキーボードのバックライトを制御することができます。D-Bus を使用する利点は、デバイスファイルへの変更が必要なく、全てのメーカーで使えることです。
   

2021年12月23日 (木) 11:30時点における版

キーボードのバックライトの輝度レベルを制御するには、さまざまな方法があります。

全メーカー共通

There are a variety ways to manage the brightness level and different helpers tools to accomplish this, such as brightnessctl or light.

The sys pseudo-file system exposes an interface to the keyboard backlight. The current brightness level can be get by reading /sys/class/leds/tpacpi::kbd_backlight/brightness. For example to get the maximum brightness level:

$ cat /sys/class/leds/tpacpi::kbd_backlight/max_brightness

To set the brightness to 1:

# echo 1 > /sys/class/leds/tpacpi::kbd_backlight/brightness

When using brightnessctl you can get a list of available brightness controls with brightnessctl --list, then to show the kbd backlight information:

$ brightnessctl --device='tpacpi::kbd_backlight' info

This will show the absolute and relative current value and the maximum absolute value. To set a different value:

$ brightnessctl --device='tpacpi::kbd_backlight' set 1

xset

Some keyboard manufactores are not recognized by brightnessctl or light, but you can use xorg-xset to control its lights if you are running Xorg.

The first parameter led turns on the led, and -led turns it off, the NUMBER parameters accepts integers for 1 to 32 (each number corresponds to a led in you system, keyboards seem to generally be number 3), or 'on' and 'off' (on will turn ALL lights on, and off will turn ALL lights off).

To turn on the lights:

$ xset led NUMBER

To turn off the lights:

$ xset -led NUMBER

D-Bus

D-Bus インタフェース経由でコンピュータのキーボードのバックライトを制御することができます。D-Bus を使用する利点は、デバイスファイルへの変更が必要なく、全てのメーカーで使えることです。

以下に Python 3 での実装例を示します。/usr/local/bin/ にスクリプトを置き、実行可能にします。/usr/local/bin/kb-light.py +/usr/local/bin/kb-light.py - を実行するキーボードショートカットを作成することでキーボードの輝度を変えることができます。

/usr/local/bin/kb-light.py
#!/usr/bin/env python3
# coding: utf-8

from sys import argv
import dbus


def kb_light_set(delta):
    bus = dbus.SystemBus()
    kbd_backlight_proxy = bus.get_object(org.freedesktop.UPower, /org/freedesktop/UPower/KbdBacklight)
    kbd_backlight = dbus.Interface(kbd_backlight_proxy, org.freedesktop.UPower.KbdBacklight)

    current = kbd_backlight.GetBrightness()
    maximum = kbd_backlight.GetMaxBrightness()
    new = max(0, current + delta)

    if new >= 0 and new <= maximum:
        current = new
        kbd_backlight.SetBrightness(current)

    # Return current backlight level percentage
    return 100 * current / maximum

if __name__ == __main__:
    if len(argv[1:]) == 1:
        if argv[1] == "--up" or argv[1] == "+":
            # ./kb-light.py (+|--up) to increment
            print(kb_light_set(1))
        elif argv[1] == "--down" or argv[1] == "-":
            # ./kb-light.py (-|--down) to decrement
            print(kb_light_set(-1))
        else:
            print("Unknown argument:", argv[1])
    else:
        print("Script takes exactly one argument.", len(argv[1:]), "arguments provided.")