initial script
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Sun, 25 Jul 2021 14:00:06 +0000 (00:00 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Sun, 25 Jul 2021 14:00:06 +0000 (00:00 +1000)
kbdo [new file with mode: 0755]

diff --git a/kbdo b/kbdo
new file mode 100755 (executable)
index 0000000..595a984
--- /dev/null
+++ b/kbdo
@@ -0,0 +1,46 @@
+#!/bin/bash
+#
+# Trigger xfce4-screenshooter on PrtSc/SysRq key
+# Doesn't consume the key!!
+# Arguments, if given, is a command to use for processing the screenshot,
+# instead of getting a dialog about it. The capture is added as an
+# additional final argument, as a file in /tmp.
+#
+# Example for simply saving it in the ~/Pictures directory.
+#   kbdo cp -t $HOME/Pictures
+#
+# Example for running custom "copying script"
+#   kbdo $HOME/bin/mycp $HOME/Pictures/snap 4
+# .. where $HOME/bin/mycp could be a file with the following line:
+#   cp $3 $1/$(printf %0${2}d.png $(ls $1|wc -l))
+# .. for saving screenshots by serial numbering instead
+#
+# Example for custom copying by inline scripting (note the backslashes):
+# kbdo 'bash -c "X(){ cp \$1 \$HOME/Pictures; }; X \$1" mycp'
+
+ARGS="$*"
+if [ -z "$ARGS" ] ; then
+    PRG=( /usr/bin/xfce4-screenshooter -w )
+else
+    PRG=( /usr/bin/xfce4-screenshooter -w -o "$ARGS" )
+fi
+
+EVL=""
+
+foo() {
+    echo $1 >&2
+}
+
+stdbuf -o0 xxd -c 24 -p < /dev/input/event0 | \
+    stdbuf -o0 sed 's/.\{32\}//;s/\(.\{12\}\).*/\1/' | \
+    while read EV ; do
+       if [ "$EV" != "000000000000" ] ; then
+           EVL+=" $EV"
+           continue
+       fi
+       if [ -z "${EVL%%*010063000100}" ] ; then
+           echo "${PRG[@]}" >&2
+           "${PRG[@]}" &
+       fi
+       EVL=""
+    done