ArticleslgStudy

science

Keystroke programming

Keystroke programming is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Keystroke programming rather than just read about it. In short: Keystroke programming describes a specific way of programming by which each keystroke on a device or application is recorded in some way and then played back so that the recorded key-presses can be repeated multiple times. Keystroke programming is most commonly but not exclusively found in programmable calculators—there are keystroke-programmable software applications, too, such as Vim.

Keystroke programming — main illustration
Keystroke programming — illustration

Key takeaways

  • Keystroke programming belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Keystroke programming to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Keystroke programming from memory before moving on to harder problems.

Reference excerpt

Keystroke programming describes a specific way of programming by which each keystroke on a device or application is recorded in some way and then played back so that the recorded key-presses can be repeated multiple times. Keystroke programming is most commonly but not exclusively found in programmable calculators—there are keystroke-programmable software applications, too, such as Vim.

TI calculator example

The Texas Instruments TI-58/TI-58C/TI-59 calculators were programmable, and program storage took the form of a sequence of codes which (mostly) corresponded to the position of keys on the calculator keypad. Here is a simplified diagram of the basic key layout:

Each key is assigned a two-digit code; for most (but not all) keys, the tens digit comes from the row number (as indicated down the left of the table) and the units digit comes from the column number (as indicated across the top of the table). Now consider a very simple program, which adds 2 to the number being displayed, and then stops. The program is entered starting from program location 000, and looks like this:

To use this program, you would enter the number n to be operated on, press RST to ensure the current program location was 000, then R/S to start execution. When the program stops (which should happen quite quickly for such a simple program), the display will be showing the number n + 2. You can see that the codes 85, 95 and 91 correspond to the positions of the keys labelled + , = and R/S on the grid above, but the code for the 2 is not 83 as you would expect from the grid position, but 02. This last code was chosen to be more easily understandable by a human trying to read the program. There is no row 0, so the codes 00 .. 09 are used to represent the keys 0 .. 9 .

Context-dependent interpretations These TI calculators allowed for addressing up to 100 data memory locations, numbered 00 to 99 (some models had a lower limit than this). A keystroke sequence like STO 4 2 (store the currently-displayed number into memory 42) would be encoded as 42 42. In this case the first 42 is the key code for the STO key, but the second 42 is not a key code, but a memory register number. The calculator knows to interpret it as such because that's what has to follow the code for the STO key. Program addresses were 3 digits, potentially allowing programs to consist of up to 1000 steps, numbered 000 to 999 (though in fact none of the models produced allowed for this maximum). A branch instruction, for example GTO 3 4 5 (unconditional branch to location 345) would be encoded as 61 03 45. In this case the hundreds digit of the branch destination is in the units digit of the second instruction byte (after the opcode), with a zero tens digit; and the remaining digits are in the third instruction byte. A code sequence like 61 11, on the other hand, represents the keystrokes GTO A , which is a branch to the location marked by the symbolic label A . The calculator can tell this is a symbolic branch, rather than a branch to a numbered location, because the tens digit of the byte immediately following the opcode is not zero. Most of the keys on the keypad can be used as symbolic labels. For example, sequences like GTO STO and GTO GTO are legitimate, provided that STO and GTO have in fact been defined as labels somewhere in the program.

Modifier keys Most of the keys had multiple functions, depending on whether INV or 2nd had been pressed beforehand. INV invoked the "inverse" (whatever that meant) of the following function, and was recorded in a program as a separate keystroke (code 22), while 2nd invoked a completely different function which was written on the keypad faceplate just above the key. For example, pressing 2nd x2 invoked the sin function, while INV 2nd x2 (or INV sin) gave you the arcsine. The code for this alternate function is derived from that of the original key function by adding 5 to the units digit (without carry to the tens digit). Thus, the key codes corresponding to the position of the 2nd key itself (21 and 26) are never used as opcodes. Here is the table of the codes produced with the 2nd prefix:

Merged keystrokes The Ind key allows for indirection: wherever a reference to a memory register or a program location is allowed, this key can be used to fetch the actual value from a memory register. For example, the key sequence RCL Ind 1 0 means to fetch the value in memory register 10, and use that value in turn as the number of a memory register whose contents are to be fetched as the current operand. However, in this case the Ind cannot be encoded as code 40, because the code sequence 43 40 would be interpreted as RCL 4 0 , not RCL Ind. But, because of the use of the 00 .. 09 codes for the 0 .. 9 keys, the codes 62–64, 72–74, 82-84 and 92 are available for other uses. So most of these are reallocated to represent op Ind sequences:

Thus, the key sequence RCL Ind 1 0 would be encoded as 73 10. Note the use of code 92 for INV SBR (return from subroutine); this was not necessary for reasons of ambiguity, but was done to save space with such a common sequence.

See also FOCAL keystroke programming Macro recorder Programming by demonstration

References

Worked examples

Example 1 — a first encounter with Keystroke programming

Start with the simplest possible case. Write down what Keystroke programming claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Keystroke programming before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Keystroke programming ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Keystroke programming

In research
Keystroke programming appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Keystroke programming in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Keystroke programming is common in secondary-school and first-year university syllabi. It links to neighbouring topics Programmable calculators, so understanding it makes those chapters shorter.
In everyday life
Look for Keystroke programming outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Keystroke programming” →

How to study Keystroke programming in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Keystroke programming means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Keystroke programming out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Keystroke programming in simple terms?

Keystroke programming describes a specific way of programming by which each keystroke on a device or application is recorded in some way and then played back so that the recorded key-presses can be repeated multiple times. Keystroke programming is most commonly but not exclusively found in programm…

Why does Keystroke programming matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Keystroke programming?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Keystroke programming.

Tags

  • Programmable calculators

Keep exploring