--- title: "Detecting Multiple Keys" id: 77882 type: "computer_media" slug: "detecting-multiple-keys" url: "http://localhost/computer_media/detecting-multiple-keys/" markdown_url: "http://localhost/computer_media/detecting-multiple-keys.md" published_at: "2026-11-19T15:04:04+00:00" modified_at: "2026-11-19T15:04:04+00:00" featured_image: url: "http://localhost/wp-content/uploads/2026/11/detecting-multiple-keys-1.png" excerpt: "See the keyboard bits the ZX81 stores in LAST_K for each key, and test for several keys held at once with a 15-byte routine." post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" 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: "Mather White" slug: "mather-white" taxonomy: "indiv" url: "http://localhost/indiv/mather-white/" genre: - name: "Utility" slug: "utility" taxonomy: "genre" url: "http://localhost/type/utility/" media_type: "Program" programmers: - name: "Mather White" slug: "mather-white" taxonomy: "indiv" url: "http://localhost/indiv/mather-white/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Detecting%20Multiple%20Keys%20%281984%29%28White%2C%20Mather%29%28TS1000%29%28US%29%28Program%29.zip" mediadate: "1984" images: - url: "http://localhost/wp-content/uploads/2026/11/detecting-multiple-keys-1.png" - url: "http://localhost/wp-content/uploads/2026/11/detecting-multiple-keys-2.png" article_media: - id: 19867 title: "Detecting Multiple Keys" type: "article" url: "http://localhost/article/detecting-multiple-keys/" media_type_tags: "Utility" license: false --- # Detecting Multiple Keys The first program shows the keyboard matrix code in the system variable LAST_K (addresses 16421 and 16422) for each key you press. Hold a key down until the numbers appear: the program prints the key, then each byte in decimal and in binary. A 0 bit marks a pressed key’s half-row or data line. Compare the patterns with the charts in the article. INKEY$ returns an empty string when more than one key is down. The second program is the article’s 15-byte machine code routine in a line 1 REM. PRINT USR 16514 gives 0 while the selected keys are all held, and 16514 otherwise. As printed, the bytes test for S, G and A together. To test other keys, POKE the complemented bit patterns into 16519 and 16523, as the article explains. In your own programs use IF NOT USR 16514 THEN … to check for two-player or combination-lock key presses. The article has you enter the bytes into the REM with a separate loader. The download has them in place. Published in Syntax February 1984 ([Detecting Multiple Keys](https://timexsinclair.com/article/detecting-multiple-keys/)). ## Source Code ``` Keyboard pattern program: 10 GOTO 1000 30 LET K$=INKEY$ 40 IF K$="" THEN GOTO 30 50 RETURN 60 SCROLL 70 LET Z=16421 80 LET A(S)=PEEK Z 90 LET A(S+S)=PEEK (Z+S) 95 PRINT K$;S$; 100 FOR D=S TO S+S 110 LET A=A(D) 120 PRINT A;S$; 130 FOR F=7 TO 0 STEP -1 140 LET X=2**F 150 PRINT A>=X; 160 IF A>=X THEN LET A=A-X 170 NEXT F 180 PRINT , 190 NEXT D 200 GOSUB 30 299 GOTO 60 1000 DIM A(2) 1100 LET S$=" " 1200 LET S=PI/PI 1500 GOSUB 30 1999 GOTO 60 Multi-key test (the line 1 REM holds the 15 bytes 42 37 64 125 230 2 192 124 230 38 192 1 0 0 201): 1 REM 123456789012345 2 PRINT USR 16514 3 SCROLL 4 GOTO 2 ```