Top Forums Shell Programming and Scripting Poll Wacom input from "libinput debug-events" in Bash Post 303039686 by mrjpaxton on Saturday 12th of October 2019 12:43:42 AM
Poll Wacom input from "libinput debug-events" in Bash


I am making a Bash shell script to grab input from libinput. There's a few reasons why I am doing it this way:
  1. Using Python with python-libinput does not work. I installed version 0.1.0 with pip, and it complains about "ContextType" not existing. So that's a no-go.
  2. I am trying to get away from my dependence on Xorg-related stuff, such as xsetwacom and xserver-input-wacom, and do things that are more compatible with Wayland.
  3. Both methods above do not have support for the four different modes when you press the center ring button on the ExpressKey pad. I plan to eventually support all of these events.

Without explaining my entire plan of this script, I figured I could ask the question that's harder for me to understand, and figure out the rest as I go along.

I want to poll the outputs from "libinput debug-events" in an infinite loop Bash script that will run in the background. This polling will happen, say, every 1 second.

This pseudocode down below can help explain what I am looking to do to start out my script:

while true; do
  sleep 1
  OUTPUT=$(libinput debug-events | grep "TABLET_PAD_BUTTON")
  case ${OUTPUT} in
  "4 pressed (mode 0)")
    echo "Button 4"
    # Etc . . .

My big problem is figuring out how to do this.

The thing is, "libinput debug-devices" works a lot like showkey or xev, but not exactly. For some reason, stdin for "TABLET_PAD_BUTTON" is "frozen" until I move the mouse around. Why this is, I have no idea. Regardless to say, I feel like I may be overcomplicating my problem, or I just don't really see a clear cut solution. Doing it this way just doesn't work right, as it is.

The libinput binary program will need to somehow exit after a period of time, because by default it is left running, so some sort of control implementation needs to exist there. Also, I notice that when it loops back to "OUTPUT=xyz" the existing variable data should be replaced by new input data again, which is great. That's exactly how it should work in that case.

Finally, this is a script that needs to run in the background (like a daemon process), and also accept input from libinput/udev devices at all times. And I'm not sure if Bash is powerful enough to tell the libinput binary to do that, is the thing.... If this really needs to be written in C, then perhaps there's no good solution here, and the thread can be closed if that's the case.

Anybody have any idea how I could approach this problem, or could even possibly provide a good bash script solution? Thank you very much in advance!

Last edited by mrjpaxton; 10-12-2019 at 02:55 AM..
Test Your Knowledge in Computers #644
Difficulty: Easy
The first web browser was called WorldWideWeb.
True or False?

9 More Discussions You Might Find Interesting

1. Programming

How to convert the "select" function into a "poll" function

i have a program using the select function but i want to convert it to poll... how can i do this? thanks in advance... :) (1 Reply)
Discussion started by: rbolante
1 Replies

2. Shell Programming and Scripting

check input = "empty" and "numeric"

Hi how to check input is "empty" and "numeric" in ksh? e.g: ./myscript.ksh k output show: invalid number input ./myscript.ksh output show: no input ./myscript.ksh 10 output show: input is numeric (6 Replies)
Discussion started by: geoffry
6 Replies

3. UNIX for Advanced & Expert Users

kernel debug:"Symbol file not found for *.ko"

When I debug vmlinux with gdb, after it connect to the target, I got below output: usbcore.ko: No such file or directory. Error while mapping shared library sections: ohci_hcd.ko: No such file or directory. Symbol file not found for usbcore.ko Symbol file not found for ohci_hcd.ko Symbol... (2 Replies)
Discussion started by: yanglei_fage
2 Replies

4. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 error12 6 error13 84 aux008 error14 29 error12 209 error34 21 error12 227 error123 22 error121 13 error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. Shell Programming and Scripting

Explaining behaviour of sudo bash "$0" "$@";

I've found this script part on the stackoverflow: if ; then sudo bash "$0" "$@"; exit "$?"; fi I realized that sudo bash "$0" "$@"; is the only needed for me. But the strange thing happens when I move this line outside the IF statement: sudo bash "$0" "$@"; stops the... (9 Replies)
Discussion started by: boqsc
9 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
after(n)						       Tcl Built-In Commands							  after(n)


after - Execute a command after a time delay SYNOPSIS
after ms after ms ?script script script ...? after cancel id after cancel script script script ... after idle ?script script script ...? after info ?id? _________________________________________________________________ DESCRIPTION
This command is used to delay execution of the program or to execute a command in background sometime in the future. It has several forms, depending on the first argument to the command: after ms Ms must be an integer giving a time in milliseconds. The command sleeps for ms milliseconds and then returns. While the command is sleeping the application does not respond to events. after ms ?script script script ...? In this form the command returns immediately, but it arranges for a Tcl command to be executed ms milliseconds later as an event handler. The command will be executed exactly once, at the given time. The delayed command is formed by concatenating all the script arguments in the same fashion as the concat command. The command will be executed at global level (outside the context of any Tcl procedure). If an error occurs while executing the delayed command then the bgerror mechanism is used to report the error. The after command returns an identifier that can be used to cancel the delayed command using after cancel. after cancel id Cancels the execution of a delayed command that was previously scheduled. Id indicates which command should be canceled; it must have been the return value from a previous after command. If the command given by id has already been executed then the after can- cel command has no effect. after cancel script script ... This command also cancels the execution of a delayed command. The script arguments are concatenated together with space separators (just as in the concat command). If there is a pending command that matches the string, it is cancelled and will never be executed; if no such command is currently pending then the after cancel command has no effect. after idle script ?script script ...? Concatenates the script arguments together with space separators (just as in the concat command), and arranges for the resulting script to be evaluated later as an idle callback. The script will be run exactly once, the next time the event loop is entered and there are no events to process. The command returns an identifier that can be used to cancel the delayed command using after can- cel. If an error occurs while executing the script then the bgerror mechanism is used to report the error. after info ?id? This command returns information about existing event handlers. If no id argument is supplied, the command returns a list of the identifiers for all existing event handlers created by the after command for this interpreter. If id is supplied, it specifies an existing handler; id must have been the return value from some previous call to after and it must not have triggered yet or been cancelled. In this case the command returns a list with two elements. The first element of the list is the script associated with id, and the second element is either idle or timer to indicate what kind of event handler it is. The after ms and after idle forms of the command assume that the application is event driven: the delayed commands will not be executed unless the application enters the event loop. In applications that are not normally event-driven, such as tclsh, the event loop can be entered with the vwait and update commands. SEE ALSO
bgerror(n), concat(n), update(n), vwait(n) KEYWORDS
cancel, delay, idle callback, sleep, time Tcl 7.5 after(n)

Featured Tech Videos

All times are GMT -4. The time now is 02:28 AM.
Unix & Linux Forums Content Copyright 1993-2019. All Rights Reserved.
Privacy Policy