You are not logged in.

#1 2013-10-02 23:47:04

Foxboron
Package Maintainer (PM)
From: Norway
Registered: 2013-06-09
Posts: 34
Website

[Solved] Dimming keyboard leds when idle? [Script Added]

Helluw.

Been spending a few hours now trying to figure out how to dim and light my keyboard leds based on activity. Found several utilities that does this for the screen brightness, even Gnome3 does this when the power is critical.
The problem is basically launching an event every X seconds there is no keyboard interaction or no activity on the screen, how can you achieve this?

Last edited by Foxboron (2013-10-04 20:47:48)

Offline

#2 2013-10-03 00:21:33

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,730
Website

Re: [Solved] Dimming keyboard leds when idle? [Script Added]

Have you considered cron?
You need to install "cronie" and run it via systemd with

 systemctl enable cronie
 sytemctl run cronie

Cron is a well documented program, so it may be easy to do what you want.
Now, I know there are other programs but I'm not familiar enough to recommend anything else smile

R.

Offline

#3 2013-10-03 00:48:02

Foxboron
Package Maintainer (PM)
From: Norway
Registered: 2013-06-09
Posts: 34
Website

Re: [Solved] Dimming keyboard leds when idle? [Script Added]

ralvez wrote:

Have you considered cron?
You need to install "cronie" and run it via systemd with

 systemctl enable cronie
 sytemctl run cronie

Cron is a well documented program, so it may be easy to do what you want.
Now, I know there are other programs but I'm not familiar enough to recommend anything else smile

R.

Well, running the event isn't really the problem. It is detecting WHEN the event should be ran. I know about cron, but AFAIK systemd solves this part quite well. Thanks anyway ^^!

Offline

#4 2013-10-04 20:39:59

Foxboron
Package Maintainer (PM)
From: Norway
Registered: 2013-06-09
Posts: 34
Website

Re: [Solved] Dimming keyboard leds when idle? [Script Added]

After some fiddling i have a rather hacky solution using some Python and inotify.

#!/usr/bin/env python
from subprocess import *
from queue import Queue
import threading
from time import time, sleep

timout = 1
q = Queue()

class MainThread(threading.Thread):
	daemon=True
	def __init__(self, q):
		threading.Thread.__init__(self)
		self.q = q

	def run(self):
		a = Popen(["inotifywait","-mrcq","/dev/input"], stdout=PIPE)
		while True:
			for i in a.stdout:
				if self.q.empty():
					self.q.put(i)
			sleep(5)

def start():
	t = MainThread(q)
	t.start()
	timr = time()
	while True:
		if not q.empty():
			res = q.get()
			call(["asus-kbd-backlight","on"])
			sleep(timout)
		else:
			if int(time() - timr) >= timout:
				call(["asus-kbd-backlight","off"])
				timr = time()
		sleep(0.5)

start()

Last edited by Foxboron (2013-10-04 20:40:19)

Offline

Board footer

Powered by FluxBB