A reckoner seed: keys, key codes named — machines/seeds/seedkeys.shoddy
seedkeys is a seed: a small file that plugs one machine's
words — its named commands — into the reckoner calculator. This one brings
keys to a prompt: KEYNAME,
KEYGLYPH and KEYIS answer what a physical key
code stands for.
This seed exists because a note was wrong.
halifax listed
keys among the machines a prompt could not reach.
The note filed it under “raw keystrokes, which
InputLine already owns” — the same live-resource heading
as the windows and the sockets. It is not one.
keys reads no keyboard and owns no device.
ClassifyKey takes a number and answers which key that
code stands for. KeyGlyph and IsKey are questions
about that answer. The whole machine is a lookup table, and its header says
“Standalone: includes nothing.”
Whatever produced the code — a scribbler event, a log file, a person
typing 262 at a prompt — is somebody else's business. So there
was never a rule in the way, only a misfiling.
“What is key code 262?” is the question. Before this seed, the only way to answer it was to write a program. Anyone reading a scribbler event log wants this answer at a prompt. So does anyone working out why a hotkey does not fire.
GameKey does not cross the bridge, and
does not need to. There is no key cell, and a type with eleven
cases would be a poor one. Every question a caller asks of a
GameKey is already answered by a string or a boolean — a plain
true-or-false value. So the three words take the code and answer
those questions directly, and ClassifyKey stays inside.
KEYNAME answers the glyph for a letter or
digit — the printed character itself — and the key's name
otherwise. That is one word rather than two because it is one question:
which key is this? An answer of "char" would only
make the caller ask again.
A key code is a whole number and nothing else. A
negative or fractional one is refused, rather than quietly reported as
"other". That is the answer that would look right and be
wrong.
> 262 KEYNAME
x: "left"
> 81 KEYNAME
x: "Q"
> 262 KEYGLYPH
x: ""
> 81 "q" KEYIS
x: True
> 9999 KEYNAME
x: "other"
KEYIS is deliberately case-insensitive: capital and small
letters match alike. A physical letter key always reports uppercase, so
matching against "q" is what a caller means.
| Word | Description |
|---|---|
| KEYNAME ( code -- str ) | Which key a physical key code stands for: "left", "right", "up", "down", "space", "enter", "esc", "tab", "back", the glyph itself for a letter or digit, or "other". |
| KEYGLYPH ( code -- str ) | The character a letter or digit key stands for, and "" for every named key and anything unmapped. KEYNAME is the one that names the rest. |
| KEYIS ( code s -- flag ) | Whether that code is the letter or digit s. Case does not matter, because a physical letter key always reports uppercase. |
| User | How | |
|---|---|---|
| halifax | The calculator's key-code words — naming a physical key code without writing a program to do it. |
A mill — a complete Shoddy program — claims this seed by folding
RckSeedKeys over its reckoner state. That is all halifax
does.
| Machine | Why | |
|---|---|---|
| cuttle | The Cell type the answers cross the bridge as. | |
| keys | The domain this seed bridges: ClassifyKey, KeyGlyph and IsKey. | |
| reckoner | RckReg and the argument readers, including RckWholeArg, which is what refuses a key code that is not one. | |
| seq | Pair, for reading the two arguments KEYIS takes. |