5 releases
new 0.2.3 | Jan 11, 2025 |
---|---|
0.2.2 | Jul 6, 2023 |
0.2.1 | Jun 26, 2023 |
0.2.0 | Jun 24, 2023 |
0.1.0 | Jun 22, 2023 |
#991 in Command line utilities
140 downloads per month
39KB
884 lines
ScriptKeys
A simple mapping from key press to Lua script. Map a key index to a Lua script to automate different tedious tasks.
Installation
cargo install scriptkeys
will pull from Crates.io for easy installation- Alternatively this can be built locally how you would expect
cargo build --release
- Locate the binary
./target/release/scriptkeys
to relevantPATH
directory
Brew and other system level packaging is likely a worthwhile investment for the future.
Configuration
Configuration location follows this logic: file name of either config.toml
or
scriptkeys.toml
in either the working directory, the ~/.config
directory, or
~/.scriptkeys
directory.
Example Configuration:
device = 'XK68JS'
[[mappings]]
key = 0
script = 'Script1.lua'
[[mappings]]
key = 1
script = 'Script2.lua'
You may also add log_level
value in the top level of the config (alongside
device
) to set the log level. Default level is Info
but you may set it to
any of the standard log
package LevelFilter
s.
Writing Scripts
Scripts are stored in either the ./.scripts
directory (where ./ is the working
directory of the binary) or in ~/.scriptkeys/scripts/
directory.
The lua scripts are straight forward and should follow this structure:
Test = Test or {}
function Test.Press()
print("Hello from the Press Key Method in Lua.")
end
function Test.Release()
print("Hello from the Release Key Method in Lua.")
end
Ensure that the script's file name is the same as the Lua table. In this case
the Lua Table is named Test
so the Lua file would need to be named Test.lua
.
The Lua Table and Lua file can be named whatever you like but they must match.
Available helper functions
Inside the Lua context there are helper functions for emulating keyboard keys, if desired. Below is a list of these.
keyClick("<char>")
keyPress("<char>")
keyRelease("<char>")
rawKeyClick(<u16>)
rawKeyPress(<u16>)
rawKeyRelease(<u16>)
hid_post_aux_key(<u32>, <bool>)
- Note: This function is MacOS only
- The first variable is the key type and the second is if the key is down or up
Example:
Test = Test or {}
function Test.Press()
keyClick("H")
keyClick("e")
keyClick("l")
keyClick("l")
keyClick("o")
keyClick("Space")
keyClick("W")
keyClick("o")
keyClick("r")
keyClick("l")
keyClick("d")
keyClick("!")
end
function Test.Release()
end
A full list of the mappings can be found in the map_str_to_key helper function
Supported Devices
- XKeys 68 JS
Dependencies
~7–40MB
~560K SLoC