--- title: "Key-Value Demonstrator" id: 77742 type: "computer_media" slug: "key-value-demonstrator" url: "http://localhost/computer_media/key-value-demonstrator/" markdown_url: "http://localhost/computer_media/key-value-demonstrator.md" published_at: "2026-11-18T16:43:01+00:00" modified_at: "2026-11-18T16:43:01+00:00" featured_image: url: "http://localhost/wp-content/uploads/2026/11/key-value-demonstrator-1.png" excerpt: "See the LAST K key-value of each ZX81 key, then try Ian Logan's machine-code keyboard scanning routine." post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" - name: "ZX81" slug: "zx81" taxonomy: "post_tag" url: "http://localhost/tag/zx81/" model: - name: "Sinclair ZX81" slug: "zx81" taxonomy: "model" url: "http://localhost/model/zx81/" - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" indiv: - name: "Ian Logan" slug: "ian-logan" taxonomy: "indiv" url: "http://localhost/indiv/ian-logan/" genre: - name: "Machine Language" slug: "machine-language" taxonomy: "genre" url: "http://localhost/type/machine-language/" media_type: "Program" programmers: - name: "Ian Logan" slug: "ian-logan" taxonomy: "indiv" url: "http://localhost/indiv/ian-logan/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Key-Value%20Demonstrator%20%281982%29%28Logan%2C%20Ian%29%28TS1000%29%28GB%29%28Program%29.zip" mediadate: "1982" images: - url: "http://localhost/wp-content/uploads/2026/11/key-value-demonstrator-1.png" - url: "http://localhost/wp-content/uploads/2026/11/key-value-demonstrator-2.png" article_media: - id: 65583 title: "Keyboard Scanning from Machine Code" type: "article" url: "http://localhost/article/keyboard-scanning-from-machine-code/" media_type_tags: "Machine Language" license: false --- # Key-Value Demonstrator Two short demonstrations from Ian Logan’s article on reading the ZX81 keyboard from machine code. The Key-Value Demonstrator scrolls up the screen showing the key you are pressing and the value in the system variable LAST K: 65535 for no key, 65015 for 1, 64503 for 2, and so on, the values a SLOW-mode machine-code program can test for. The second program is Logan’s FAST/SLOW keyboard scanning routine, a copy of Sinclair’s own method that handles multiple keys and debounce. The BASIC POKEs the 36 bytes from a hex string into the line 10 REM, then calls it in a loop, so each key you press is printed down the screen. [Editor’s note: as printed, the routine ends 46 75 D7 C9, which prints the wrong characters. The file in the download ends 7E 00 D7 C9 (LD A,(HL) instead of LD B,(HL); LD (HL),L), which prints the key pressed as the article describes. Line 30 of the listing below is as printed.] Published in Syntax July 1982 ([Keyboard Scanning from Machine Code](https://timexsinclair.com/article/keyboard-scanning-from-machine-code/)). ## Source Code ``` KEY-VALUE DEMONSTRATOR 10 SCROLL 20 PRINT INKEY$;TAB 7;PEEK 16421+256*PEEK 16422 30 GOTO 10 FAST/SLOW KEYBOARD SCANNING 10 REM 123456789012345678901234567890123456 20 REM NOW ENTER THE ROUTINE 30 LET A$="213B40CB7ECC2902CB4628FCED4B2540CBC0FDCB3B863EFF322740CDBD0730E04675D7C9" 40 FOR A=1 TO 36 50 POKE 16513+A,16*(CODE A$(A*2-1)-28)+CODE A$(A*2)-28 60 NEXT A 100 REM NOW CALL THE ROUTINE 110 SCROLL 120 RAND USR 16514 130 GOTO 100 ```