0

I am trying to enable my keyboard LED's on Arch Linux and here I found this nice script:

#!/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.")

which works if I put it in ~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/, make it executable and start it with one of the commands below:

~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py +
~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py -

Problem occurs when I try to implement this inside my i3 configuration file ~/.config/i3/config like this (user manual):

bindcode 229 exec "~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py -"
bindcode 230 exec "~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py +"

I can confirm bindcode 229 and bindcode 230 numbers if I exit my i3 window manager, use command showkey and then press the keys that I want to bind commands to. These two keys haven't been used anywhere else but this fails to work.

  • 2
    The keycodes and scancodes shown by showkey are only for the text console. They do not necessarily match the keycodes used in X11 (i.e. the GUI). To get the correct codes for use with i3, you can use the tool xev (from within a terminal emulator in an active X11 session, e.g. with i3 running). Used as xev -event keyboard it will show only keyboard events. Case in point: the correct X11 keycodes for brightness control seem to be 232 and 233. – Adaephon Sep 27 '16 at 12:08
  • I found out about xev later. And you are correct - I used wrong keycodes, because I looked in console. I read somewhere that I have to move to console in order for showkey to work. =) – 71GA Sep 29 '16 at 4:23
0

Solution to this answer was like this:

bindsym XF86KbdBrightnessDown exec --no-startup-id ~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py -
bindsym XF86KbdBrightnessUp exec --no-startup-id ~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py +

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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