nkb send
Wpisuje jedną wartość z paczki albo zrobioną dla limitu długości w pole, które ma fokus klawiatury. Na Windows, macOS i Linuksie.
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]
Jak go używać?
Podaj paczkę i, z --index, którą wartość. Polecenie domyślnie czeka trzy sekundy, żeby był czas kliknąć w pole, a potem wpisuje tam wartość:
$ nkb send magic-values --index 2 --delay 3
Wartość trafia do okna z fokusem, a nie na standardowe wyjście, a wszystko, co mówi polecenie, idzie na standardowe wyjście błędów. Dodaj --clear, żeby najpierw wyczyścić bieżący wiersz pola klawiszami Home, Shift+End i Delete, tak jak paleta robi domyślnie. Bez tej opcji jedyne wysyłane klawisze to znaki samej wartości. Tabulator w wartości jest naciskany jako klawisz Tab, a znak nowej linii jako Enter, więc w polu jednowierszowym mogą przenieść fokus albo wysłać formularz, o czym mówią Uczciwe ograniczenia.
Czy wpisze wartość dla limitu długości?
Tak. Zamiast paczki podaj limit, opcjami nkb boundary, a --index wskaże miejsce wartości w kolejności, w jakiej wypisuje je tamto polecenie. Tutaj --index jest wymagane, bo pierwsza wartość jest pusta:
$ nkb send --max-length 50 --unit bytes --index 10
To two-byte-51, jedna litera a i dwadzieścia pięć liter dwubajtowych: 51 bajtów, jeden ponad limit. Po wartości polecenie mówi, co pole trzymające się limitu powinno z nią zrobić, tym samym zdaniem, które cytuje blok do zgłoszenia. Numer za ostatnią wartością kończy się kodem wyjścia 3 jeszcze przed odliczaniem, tak samo jak 0.
Kiedy odmawia?
Odmawia, zamiast zgadywać, a każda odmowa kończy się kodem wyjścia 4:
- gdy na klawiaturze wciśnięty jest Ctrl, Alt, Shift albo Win, po odczekaniu do dwóch sekund na ich puszczenie, bo wartość zamieniłaby się w skróty,
- w oknie działającym z wyższymi uprawnieniami niż
nkb, na przykład w aplikacji uruchomionej jako administrator, bo Windows odrzuciłby naciśnięcia bez słowa, - gdy fokus klawiatury jest na przycisku, odnośniku, elemencie listy albo stronie, której nie da się edytować, bo klawisze działają tam na tę kontrolkę.
Gdy nie potrafi rozpoznać, co ma fokus, wysyła. Z --clear czyści tylko fokus, o którym wie na pewno, że jest polem tekstowym, i nigdy terminal, gdzie te klawisze trafiają do programu, który w nim działa. Gdy pomija czyszczenie, mówi o tym, a wartość dochodzi do tego, co już było w polu.
Czy mogę go zatrzymać?
Naciśnij Escape. Nic więcej nie zostanie wpisane, polecenie powie, ile z wartości dotarło, i zakończy się kodem 4. Escape należy do polecenia tylko w trakcie wpisywania. Przed i po klawisz należy do aplikacji.
Czego potrzebuje każdy system?
Windows nie potrzebuje niczego. Na macOS program, z którego uruchamiasz nkb, czyli dla polecenia wpisanego w terminalu ten terminal, potrzebuje uprawnienia dostępności (Accessibility). Bez niego nkb mówi, co włączyć, niczego nie wysyła i kończy się kodem 4.
Na Linuksie pod X11 potrzebuje lokalnego wyświetlacza i nie wpisuje niczego na zdalny. Pod Waylandem przekazuje tekst metodzie wprowadzania pulpitu, IBus, więc potrzebuje demona IBus, i mówi, że wartość została przekazana, a nigdy, że jest w polu, bo pulpit nie mówi, czy jakieś pole miało fokus. Tam --clear potrzebuje zgody pulpitu na naciskanie klawiszy. Pulpit pyta o nią w osobnym oknie za pierwszym razem, a nkb mówi, że czeka.
Tam, gdzie system nie ma sposobu, polecenie to mówi i kończy się kodem 4. Więcej mówią Uczciwe ograniczenia.
Opcje
Kody wyjścia
Pomoc tego polecenia nie wymienia własnych kodów wyjścia. Liczby znaczą to samo w każdym poleceniu: Kody wyjścia
Pomoc, tak jak wypisuje ją program
Co wypisuje nkb send --help (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.