WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: actkbd and udev  (Read 3604 times)

Offline parky_dw

  • Newbie
  • *
  • Posts: 33
actkbd and udev
« on: December 29, 2017, 04:36:58 PM »
I've recently used actkbd to set things up so that I can do a screen dump by just hitting the PrintScreen key on my keyboard.  At the moment I have to start actkbd with an explicit path:

actkbd -D -q -d /dev/input/event2

The documentation suggests that way to start the daemon so that it finds the right path for the keyboard is via udev.  It's not working for me.  Syslog shows that the rules file is being processed, but I never end up with a running daemon.  Any ideas?
Working actkdb.conf file is in the default location of /usr/local/etc.
Rules file is in /etc/udev/rules.d
File is:

#udev  for keyboards
ACTION=="add", SUBSYSTEM=="input", KERNEL=="event[0-9]*", GOTO="_INPUT_"
GOTO "_END_"

LABEL="_INPUT_"
DRIVER=="actkdb", GOTO="_KBD_"
GOTO "_END_"

LABEL="_KBD_"
RUN+="/usr/local/sbin/actkbd -q -D

LABEL="_END_"



I did add a couple of "RUN+=touch" commands to the rules file to see if the branches were being followed and the "touched" files did appear in /tmp.

I'm running Tiny Core 8.2.1 (32-bit).

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: actkbd and udev
« Reply #1 on: December 30, 2017, 05:34:22 AM »
You seem to have a typo in your DRIVER part.
The only barriers that can stop you are the ones you create yourself.

Offline parky_dw

  • Newbie
  • *
  • Posts: 33
Re: actkbd and udev
« Reply #2 on: December 30, 2017, 10:50:36 AM »
Typo corrected - made no difference.

I also have another issue - things work fine if I start actkbd manually from a terminal window.  Put the same invocation in bootlocal.sh and it starts up ok but nothing happens when the Print Screen button is pressed.  Ho-Hum!

Maybe time to look at the source and invoke (or add) some debugging messages....

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: actkbd and udev
« Reply #3 on: December 30, 2017, 10:58:49 AM »
Hi parky_dw
You stated:
I've recently used actkbd to set things up so that I can do a screen dump by just hitting the PrintScreen key on my keyboard.  At the moment I have to start actkbd with an explicit path:

actkbd -D -q -d /dev/input/event2

In your udev rules you have this:
Code: [Select]
LABEL="_KBD_"
RUN+="/usr/local/sbin/actkbd -q -D
What I don't uderstand is how is the  /dev/input/event2  parameter being passed to the  RUN  line?

Offline parky_dw

  • Newbie
  • *
  • Posts: 33
Re: actkbd and udev
« Reply #4 on: December 30, 2017, 12:28:37 PM »
Me as well!  I've done nothing involving udev before and am learning as I go along.  What's presented here is a slightly modified version of the sample rule given on the github website: https://github.com/thkala/actkbd/blob/master/samples/udev.rules . The README file implies that if you use udev to launch actkbd then you don't have to to do the detective work to find out which is the correct eventN for it to use.

Quote
Update: On newer kernels several special buttons (like the Power switch) may appear as input devices as well. There is no way for the auto-detection code to tell them apart and it is quite possible that the actual keyboard will not be the one actkbd will select. Using udev to start actkbd is the best way to avoid this problem.

BTW: The issue I'm having with bootlocal.sh looks to be an issue with screenshot.sh. This has a quick check at the start that the environment variable DISPLAY is there.  If it isn't, it doesn't run.  My guess (still to be verified) is that it's not there in the environment within which  actkydb is run on boot-up,  as opposed to when actkybd is started from a logged-on user's console.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: actkbd and udev
« Reply #5 on: December 30, 2017, 01:29:19 PM »
Try editing the command in actkbd's config file to "DISPLAY=:0 screenshot.sh". Since that runs as root, but the X instance is started for user tc, you may also need to handle the XAUTHORITY things so root can access tc's display. I don't recall offhand the specifics.
edit: or run it as user tc, via su.

Udev can pass the device name to the command.
The only barriers that can stop you are the ones you create yourself.

Offline parky_dw

  • Newbie
  • *
  • Posts: 33
Re: actkbd and udev
« Reply #6 on: December 31, 2017, 05:38:43 AM »
Well things have changed direction a bit from my original question about udev.  I'm currently chasing the bootlocal.sh issue where it turns out the problem probably lies with the context in which screenshot.sh is being executed.  Having turned on logging and also extended the error reporting in actkbd I can see:

When I hit the Print Screen key actkbd definitely runs screenshot.sh which returns an error code of 1. (If I change the exit code on the first line of the script to 5 I get a return code of 5).
If I delete the first line of screenshot.sh I still get a return code of 1.  ("Operation not permitted?").

As things work if I start actkbd manually I may park this issue for now - unless anybody has any insights?

BTW: Early on in this saga, noticing that Xvesa was being started after actkbd, I did try starting after a delay using the line:

(sleep 15; /usr/local/sbin/actkbd -D -q -d /dev/input/event2) &

in bootlocal.sh in case that was a factor.  It made no difference.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: actkbd and udev
« Reply #7 on: December 31, 2017, 11:02:53 AM »
Hi parky_dw
I'm not following why you want to run  screenshot.sh  from  bootlocal.sh. At any rate, that won't work since  screenshot.sh
requires  X  to be up and running in order to work.

Maybe try starting  actkbd  after  X  is up and running. Create a file containing:
Code: [Select]
/usr/local/sbin/actkbd -D -q -d /dev/input/event2 &and place it in  ~/.X.d. The filename can be anything you want. It will run automatically after  X  is up.

Offline parky_dw

  • Newbie
  • *
  • Posts: 33
Re: actkbd and udev
« Reply #8 on: December 31, 2017, 12:39:34 PM »
Where I started was I wanted to be able to just hit the Print Screen key on the keyboard to get a screen dump.  That led me to actkbd and screenshot.sh. bootlocal.sh is the normal way to automatically have stuff running you want - in this case actkbd. It is only later (when X is running) that screenshot.sh is called in response to my hitting the Print Screen key.

Poking around a little more I've discovered that the keyboard apparently always has the entry EV=120013 in the /proc/bus/devices file[1].  I've just hacked out a simple bit of perl to autodetect the correct event and to launch actkbd.  Ideally the autodetect code in the linux.c file should do this. (I used perl as I'm more familiar with it than shell script).

Code: (perl) [Select]
#!/usr/local/bin/perl
use strict;
use warnings;

# Scan the file /proc/bus/input/devices to find the eventN queue for the keyboard,
# and then launch actkbd.
#
# Keyboard can apparently can be identified by the entry where EV=120013.

open(DEVICES, '<', "/proc/bus/input/devices" ) || die ("Can't open devices file\n");
my $line;
while( $line=<DEVICES> ) {
my $event;
next if( !($line =~ m/^H:\sHandlers=.*kbd.*(event[0-9]+)/ ));
$event = $1;
$line=<DEVICES>; # discard next line
$line=<DEVICES>;
if( $line =~ m/EV=120013/ ) {
print "Launching actkbd on $event\n";
exec "sudo /usr/local/sbin/actkbd -D -q -d /dev/input/$event";
}
}

So I'm almost home.   I've got a way now that looks like it selects the correct eventN file, which just leaves me with the more trivial job of starting it manually.

FYI: On the machine I've been trying things out on - boot from the machine's flash drive and it's event2 I need, boot from a USB Pen Drive and it's event3.

[1]https://unix.stackexchange.com/questions/74903/explain-ev-in-proc-bus-input-devices-data

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: actkbd and udev
« Reply #9 on: December 31, 2017, 01:10:58 PM »
Hi parky_dw
Quote
which just leaves me with the more trivial job of starting it manually.
Have you tried launching it from  ~/.X.d  as suggested in reply #7?

Offline parky_dw

  • Newbie
  • *
  • Posts: 33
Re: actkbd and udev
« Reply #10 on: December 31, 2017, 01:44:29 PM »
Thanks for reminding me.  A quick check and that appears to work.

Regards, David

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: actkbd and udev
« Reply #11 on: December 31, 2017, 01:59:07 PM »
Hi parky_dw
Glad to hear that worked.

Quote
Poking around a little more I've discovered that the keyboard apparently always has the entry EV=120013 in the /proc/bus/devices file[1].
Yup, and you could probably also identify it by the word  keyboard  in the  Name=  field.