Typing spike: learn it in five levels

Provided by xBraan1

A small program that types code into VS Code, saves it, reads it back and checks every character. You will use it to see how that works and where it goes wrong.

python typing_spike.py selfcheck
python typing_spike.py probe

Start here

This takes about 15 minutes. You need a Windows PC with Python 3.10 or newer and VS Code with the code command on PATH.

  1. Put typing_spike.py in a folder. Add test_typing_spike.py too if you plan to reach Level 4.
  2. Open a normal terminal there, not an administrator one, and run python typing_spike.py selfcheck. It reports what it found and types nothing.
  3. Run python typing_spike.py probe. A new VS Code window opens, you press Enter in the terminal, and the script types one short file. The whole probe takes about ten seconds. Keep your hands off the keyboard, and hold Esc to stop.
  4. Read the line that says PASS or FAIL. That is your first result. The levels below show what to do with it.

How it works

How the spike types and checks one file Eight steps: corpus, chunks, gate, key events, SendInput, save, read back, compare. Steps 2 to 5 repeat for every chunk. 1 Corpus2,000 lines, five languages, built in code 2 ChunksThe text is cut into pieces of 24 characters 3 GateVS Code in front? Esc held? Otherwise stop. 4 Key eventsText as Unicode events, Enter as a key press 5 SendInputWindows delivers the keys to VS Code 6 SaveCtrl+S writes the file to disk 7 Read backThe script reads the saved file itself 8 ComparePASS, or a named problem such as EXTRA repeats for each chunk

The gate runs before every chunk, so typing stops the moment VS Code loses focus or you hold Esc. The script trusts nothing until it has read the saved file back from disk.

Five levels

Open one level at a time and tick it when its last line is true for you. 0 of 5 levels done. Ticks stay on this device.

Level 0: Orientation0.5 h

Learn what the tool does and what it leaves alone.

Provided by xBraan1

Level 1: Run it1.5 h

Get real results and learn to read them.

Provided by xBraan1

Level 2: Experiment2.5 h

Learn what changes the result. Write a prediction before each run.

Provided by xBraan1

Level 3: Read the code3 h

Follow one character from the corpus to the comparison, in five passes of about 35 minutes.

  1. The corpus and TYPING_PROFILE.
  2. text_to_events and the INPUT structures.
  3. WindowsBackend: the foreground check and SendInput.
  4. type_text, type_file and compare.
  5. The sweep logic and the report files.

Answer these as you go. Why Unicode events? Why check focus before every chunk? Why read the file from disk instead of asking the editor? Why must INPUT be 40 bytes on 64-bit Windows?

Provided by xBraan1

Level 4: Change it3 h

Prove you understand it by changing it safely. Run python -m unittest -v test_typing_spike first so you know the starting point.

Provided by xBraan1

A 10.5-hour day

The five levels add up to 10.5 hours. The tool types for about 1.5 of them. The other nine hours are you reading, predicting and writing, which is where the understanding comes from.

Each key is 30 minutes. Amber keys are the tool typing while you watch. Open keys are you.

Work in blocks of 50 minutes with 10 off. Four habits keep a long day useful.

10.5 hours is a ceiling. When a level’s last line is true, move on early.

Reading a result

ShownWhat it means and what to try
PASSThe files match the source, line endings aside. Raise --rate in steps.
EMPTYNothing reached the file. VS Code may be elevated, another window may have had focus, or the save did not happen.
EXTRAThe editor added text. Look at auto-closing, auto-indent, suggestions and extensions.
MISSINGInput was dropped. Lower --rate or --chunk.
DIFFERENTSame length, different characters. Lower the rate and look at extensions.
ABORTEDThe run stopped early. Read the detail line: Esc, a focus change or a SendInput error.

Ground rules