aboutsummaryrefslogtreecommitdiff
path: root/utils/sendkeys.awk
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2025-09-24 05:25:39 +0200
committersrdusr <trevorgray@srdusr.com>2025-09-24 05:25:39 +0200
commita1627ac743289e768b138f1a60753a62e0869cc4 (patch)
tree92ab373442943f621bb26b3b284bb1da90e2923a /utils/sendkeys.awk
parentfdb0eb921205c34fb6ff5728727a097767ffae5a (diff)
downloaddotfiles-a1627ac743289e768b138f1a60753a62e0869cc4.tar.gz
dotfiles-a1627ac743289e768b138f1a60753a62e0869cc4.zip
Update/Overhaul
Diffstat (limited to 'utils/sendkeys.awk')
-rwxr-xr-xutils/sendkeys.awk86
1 files changed, 86 insertions, 0 deletions
diff --git a/utils/sendkeys.awk b/utils/sendkeys.awk
new file mode 100755
index 0000000..16a3fa9
--- /dev/null
+++ b/utils/sendkeys.awk
@@ -0,0 +1,86 @@
+#!/usr/bin/env awk -f
+#
+# AWK script to send multiple `sendkey` commands to a QEMU virtual machine.
+# It writes at a rate of roughly 40 keys per second, due to lower delays
+# resulting in garbage output.
+#
+# It makes use of a TCP client created by an external utility, such as OpenBSD
+# Netcat, to interact with QEMU's monitor and send a stream of `sendkey`
+# commands. This is a practical way to transfer a small file or to script
+# interactions with a terminal user interface.
+
+BEGIN {
+ # Set default delay if not provided via command-line args
+ if (!delay) {
+ delay = 0.025
+ }
+
+ # Define key mappings for common characters and symbols
+ key["#"] = "backspace"
+ key[" "] = "tab"
+ key[" "] = "spc"
+ key["!"] = "shift-1"
+ key["\""] = "shift-apostrophe"
+ key["#"] = "shift-3"
+ key["$"] = "shift-4"
+ key["%"] = "shift-5"
+ key["&"] = "shift-7"
+ key["'"] = "apostrophe"
+ key["("] = "shift-9"
+ key[")"] = "shift-0"
+ key["*"] = "shift-8"
+ key["+"] = "shift-equal"
+ key[","] = "comma"
+ key["-"] = "minus"
+ key["."] = "dot"
+ key["/"] = "slash"
+ key[":"] = "shift-semicolon"
+ key[";"] = "semicolon"
+ key["<"] = "shift-comma"
+ key["="] = "equal"
+ key[">"] = "shift-dot"
+ key["?"] = "shift-slash"
+ key["@"] = "shift-2"
+
+ # Map numbers
+ for (i = 48; i < 48 + 10; ++i) {
+ number = sprintf("%c", i)
+ key[number] = number
+ }
+
+ # Map letters A-Z, including shift
+ for (i = 65; i < 65 + 26; ++i) {
+ key[sprintf("%c", i)] = sprintf("shift-%c", i + 32)
+ }
+
+ # Other symbols
+ key["["] = "bracket_left"
+ key["\\"] = "backslash"
+ key["]"] = "bracket_right"
+ key["^"] = "shift-6"
+ key["_"] = "shift-minus"
+ key["`"] = "grave_accent"
+ key["{"] = "shift-bracket_left"
+ key["|"] = "shift-backslash"
+ key["}"] = "shift-bracket_right"
+ key["~"] = "shift-grave_accent"
+ key[""] = "delete"
+
+ # Handle Super and Caps Lock key mappings (for remapping Caps to Super)
+ key["capslock"] = "super"
+ key["super"] = "super"
+
+ # Handle other keys if needed
+}
+
+{
+ split($0, chars, "")
+ for (i = 1; i <= length($0); i++) {
+ # Print sendkey command for the character, mapping it through the key[] array
+ if (key[chars[i]] != "") {
+ printf("sendkey %s\n", key[chars[i]])
+ }
+ system("sleep " delay) # Sleep for the defined delay
+ }
+ printf "sendkey ret\n" # Send "return" (enter) key at the end
+}