nkb send
Type one value of a pack, or one made for a length limit, into the field that has the keyboard focus. On Windows, macOS and Linux.
nkb send <pack> [--index N] [--delay S] [--clear] [--team-folder <folder>]
nkb send [--max-length N] [--min-length N] [--unit U] --index N
[--delay S] [--clear]
How do I use it?
Name the pack and, with --index, which value. The command waits three seconds by default so you can click into the field, then types the value there:
$ nkb send magic-values --index 2 --delay 3
The value goes to the focused window, not to standard output, and everything the command says is on standard error. Add --clear to clear the current line of the field first with Home, Shift+End and Delete, the way the palette does by default. Without it, the only keys sent are the value’s own characters. A tab in the value is pressed as the Tab key and a line feed as Enter, so in a single-line field they may move the focus or send the form, as Honest limits explains.
Can it type a value for a length limit?
Yes. Give the limit instead of a pack, with the options of nkb boundary, and --index for the place of the value in the order that command prints them. --index is needed here, because the first value is the empty one:
$ nkb send --max-length 50 --unit bytes --index 10
That is two-byte-51, one letter a and twenty-five two-byte letters: 51 bytes, one over the limit. After the value the command says what a field that keeps to the limit should do with it, the sentence a report block quotes. A number past the last value ends with exit code 3 before the countdown, and so does 0.
When does it refuse?
It refuses rather than guesses, and every refusal ends with exit code 4:
- while Ctrl, Alt, Shift or Win is held on the keyboard, after waiting up to two seconds for them to come up, because the value would turn into shortcuts,
- in a window running with higher privileges than
nkb, such as an application started as administrator, because Windows would drop the keystrokes without a word, - when the keyboard focus is on a button, a link, a list item or a page that is not editable, because keys there act on that control.
Where it cannot tell what has the focus, it sends. With --clear it clears only a focus it can confirm is a text field, and never a terminal, where those keys go to the program running in it. When it skips the clearing it says so, and the value goes in on top of what was there.
Can I stop it?
Press Escape. Nothing more is typed, the command says how much of the value arrived, and it exits with 4. Escape belongs to the command only while it types. Before and after, the key is the application’s.
What does each system need?
Windows needs nothing. On macOS the program you run nkb from, a terminal for a command typed there, needs the Accessibility permission. Without it nkb says what to turn on, sends nothing and exits with 4.
On Linux under X11 it needs a local display, and it types nothing for a remote one. Under Wayland it hands the text to the desktop’s input method, IBus, so it needs an IBus daemon, and it says the value was handed over, never that it is in the field, because the desktop does not say whether a field had the focus. There --clear needs the desktop’s permission to press keys. The desktop asks for it in a window of its own the first time, and nkb says it is waiting.
Where a system has no way, the command says so and exits with 4. Honest limits says more.
Options
Exit codes
This command's help names no exit codes of its own. The numbers mean the same for every command: Exit codes
The help, as the program prints it
What nkb send --help prints, from nkb 0.4.0.
nkb send - type one value into the focused field
Usage:
nkb send <pack> [--index N] [--delay S] [--clear] [--team-folder <folder>]
nkb send [--max-length N] [--min-length N] [--unit U] --index N
[--delay S] [--clear]
Put one value into whatever field has the keyboard focus: a value of a
pack, or one of the values nkb boundary makes for a length limit.
Packs come from three places: the ones built in, the team folder (from
--team-folder or the settings file) and your own folder beside the
settings file. A pack in a folder is used instead of a built-in pack of
the same name, and an own pack instead of a team pack.
A limit takes the place of the pack. Its values are the ones nkb boundary
prints for the same limit, in the same order, and --index says which one,
so it is needed. After the value the command says whether a field that
keeps to the limit should take it.
Options:
--index N which value, counting from 1 in the pack's own order
(default: 1), or in the order nkb boundary prints the
values of a limit (needed then). The order of values is
the order of testing.
--max-length N the most the field takes, from 1 to 100000: type a value
made for this limit instead of a value of a pack
--min-length N the least the field takes, from 1 to 100000
--unit U what the limit is counted in: graphemes (the default),
code-points, utf16 or bytes
--delay S seconds to wait first, so you can focus the target
(default: 3). Use 0 when something else focuses it.
--clear press Home, Shift+End, Delete first, clearing the current
line of the field. Never selects beyond the line, so a
multi-line field keeps its other lines. Without this switch
the only keys sent are the value's own characters.
--team-folder <folder> Read the team's packs from this folder instead
of the one the settings file names. A relative path is
read from the current folder
-h, --help Show this help and exit with 0
The value goes to the focused window, not to standard output.
Everything you read here is on standard error.
Nothing is sent while Ctrl, Alt, Shift or Win is held on the keyboard:
the command waits up to two seconds for them to come up, then refuses.
Nothing is sent to a window running with higher privileges than nkb,
such as an application started as administrator: the system would drop
the keystrokes without a word, so the command refuses and exits with 4.
Nothing is sent when the keyboard focus is on a button, a link, a list item
or a page that is not editable: keys there act on that control, so the
command refuses and exits with 4. Where it cannot tell, it sends.
Press Escape to stop a send in progress: nothing more is typed, the command
says how much arrived and exits with 4. Escape belongs to the command only
while it types - before and after, the key is the application's.