Crates.io | scriptkeys |
lib.rs | scriptkeys |
version | 0.2.2 |
source | src |
created_at | 2023-06-22 03:46:51.762558 |
updated_at | 2023-07-06 17:26:27.771612 |
description | ScriptKeys allows you to easily build macros (in Lua) on every key press for the supported devices. |
homepage | https://mattstone.io/projects/scriptkeys/ |
repository | https://github.com/bigmstone/scriptkeys.git |
max_upload_size | |
id | 896869 |
size | 77,756 |
A simple mapping from key press to Lua script. Map a key index to a Lua script to automate different tedious tasks.
cargo install scriptkeys
will pull from Crates.io for easy installationcargo build --release
./target/release/scriptkeys
to relevant PATH
directoryBrew and other system level packaging is likely a worthwhile investment for the future.
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'
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.
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>)
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