1.\" $OpenBSD: usbhidaction.1,v 1.16 2022/03/31 17:27:28 naddy Exp $
2.\" $NetBSD: usbhidaction.1,v 1.6 2002/01/18 14:38:59 augustss Exp $
3.\"
4.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Lennart Augustsson (lennart@augustsson.net).
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29.\" POSSIBILITY OF SUCH DAMAGE.
30.\"
31.Dd $Mdocdate: March 31 2022 $
32.Dt USBHIDACTION 1
33.Os
34.Sh NAME
35.Nm usbhidaction
36.Nd perform actions according to USB HID controls
37.Sh SYNOPSIS
38.Nm
39.Op Fl div
40.Fl c Ar config-file
41.Fl f Ar device
42.Ar arg ...
43.Sh DESCRIPTION
44.Nm
45can be used to execute commands when certain values appear on HID controls.
46The normal operation for this program is to read the configuration file
47and then become a daemon and execute commands as the HID items specify.
48If a read from the HID device fails, the program dies; this will make it
49die when the USB device is unplugged.
50.Pp
51The options are as follows:
52.Bl -tag -width Ds
53.It Fl c Ar config-file
54Specify a path name for the config file.
55.It Fl d
56Toggle the daemon flag.
57.It Fl f Ar device
58Specify a path name for the device to operate on.
59If
60.Ar device
61is numeric, it is taken to be the USB HID device number.
62If it is a relative path, it is taken to be the name of the device under
63.Pa /dev .
64An absolute path is taken to be the literal device pathname.
65.It Fl i
66Ignore HID items in the config file that do not exist in the device.
67.It Fl v
68Be verbose, and do not become a daemon.
69.El
70.Pp
71The config file will be re-read upon receiving
72.Dv SIGHUP .
73.Sh CONFIGURATION
74The configuration file has a very simple format.
75Each line describes an action; if a line begins with a whitespace
76it is considered a continuation of the previous line.
77Lines beginning with `#' are considered as comments.
78.Pp
79Each line has three parts: a name of a USB HID item, a value for that item,
80and an action.
81There must be whitespace between the parts.
82.Pp
83The item names are similar to those used by
84.Xr usbhidctl 1 ,
85but each part must be prefixed by its page name.
86.Pp
87The value is simply a numeric value.
88When the item reports this value, the action will be performed.
89If the value is `*', it will match any value.
90.Pp
91The action is a normal command that is executed by using
92.Xr fork 2 .
93Before it is executed some substitution will occur:
94`$n' will be replaced by the nth argument on the
95command line, `$V' will be replaced by the numeric value
96of the HID item, `$N' will be replaced by the name
97of the control, and `$H' will be replaced by the name
98of the HID device.
99.Sh FILES
100.Pa /usr/share/misc/usb_hid_usages
101The HID usage table.
102.Sh EXAMPLES
103The following configuration file can be used to control the
104master volume and muting of an
105.Xr azalia 4
106device using the multimedia keys on a Belkin USB keyboard.
107.Bd -literal -offset indent
108# The volume range is 0..1. Moving 0.05 volume steps, each keypress
109# moves quickly through the volume range but still has decent
110# granularity.
111Consumer:Volume_Increment					   1
112	sndioctl -f $1 output.level=+0.05
113Consumer:Volume_Decrement					   1
114	sndioctl -f $1 output.level=-0.05
115Consumer:Mute							   1
116	sndioctl -f $1 output.mute=!
117.Ed
118.Pp
119A sample invocation using this configuration would be
120.Bd -literal -offset indent
121$ usbhidaction -f /dev/uhid1 -c conf snd/0
122.Ed
123.Sh SEE ALSO
124.Xr usbhidctl 1 ,
125.Xr usbhid 3 ,
126.Xr uhid 4 ,
127.Xr usb 4
128.Sh HISTORY
129The
130.Nm
131command first appeared in
132.Ox 3.2 .
133