Programming Tips: Testing modified Electron editing keys

on-topic acorn-related discussions not covered by the other forums
Post Reply
User avatar
jgharston
Posts: 3927
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Programming Tips: Testing modified Electron editing keys

Post by jgharston » Thu Apr 02, 2020 10:12 pm

Chatting with Dave H earlier reminded me of a programming tip.

On the Electron the editing keys are shared with character keys, so you normally can't detect modified editing keys (eg Shift+Dowm, Ctrl+Right, etc) in the same way as on other computers by using *FX4,1 or *FX4,2.

However, if your program doesn't use the [ ^ | _ ` ] ~ \ } { keys then you can test for them and if running on an Electron translate them to the normal editing keycode or character codes.

The first method is to translate them to the *FX4,1 character codes.

In program startup use:
*FX4,1

When reading keypresses use:
K%=GET
IF INKEY-256=1:A%=INSTR("[^|_`]~\}{",CHR$K%)-1:IF A%>-1:K%=&87+A%MOD5


This translates modified editing keys to the standard *FX4,1 values of &87-&8B, and you can test for SHIFT and CTRL with the normal INKEY-1 and INKEY-2 calls, as in this demo:

10 REM Electron cursor keys with *FX4,1
20 :
30 *FX4,1
40 REPEAT
50 K%=GET
60 IF INKEY-256=1:A%=INSTR("[^|_`]~\}{",CHR$K%)-1:IF A%>-1:K%=&87+A%MOD5
70 IF INKEY-1:PRINT "Shift+";
80 IF INKEY-2:PRINT "Ctrl+";
90 IF K%=&87:PRINT "COPY";
100 IF K%=&88:PRINT "LEFT";
110 IF K%=&89:PRINT "RIGHT";
120 IF K%=&8A:PRINT "DOWN";
130 IF K%=&8B:PRINT "UP";
140 PRINT
150 UNTIL 0


The second method is to translate them to the *FX4,2 keycodes.

In program startup use:
*FX4,2
FOR A%=8 TO 11:OSCLI "FX"+STR$(217+A%)+","+STR$(A%*16):NEXT


When reading keypresses use:
K%=GET
INKEY-256=1:A%=INSTR("[^|_`]~\}{",CHR$K%)-1:IF A%>-1:K%=&9B+(A%DIV5)*16+A%MOD5


This translates modified editing keys to the standard *FX4,2 keycodes where b5=CTRL, b4=SHIFT, b3-b0=keypress, as in this demo:

200 REM Electron cursor keys with *FX4,2
210 :
220 *FX4,2
230 FOR A%=8 TO 11:OSCLI "FX"+STR$(217+A%)+","+STR$(A%*16):NEXT
240 REPEAT
250 K%=GET
260 IF INKEY-256=1:A%=INSTR("[^|_`]~\}{",CHR$K%)-1:IF A%>-1:K%=&9B+(A%DIV5)*16+A%MOD5
270 IF (K% AND &F0)=&90:PRINT "Shift+";
280 IF (K% AND &F0)=&A0:PRINT "Ctrl+";
290 IF (K% AND &8F)=&8B:PRINT "COPY";
300 IF (K% AND &8F)=&8C:PRINT "LEFT";
310 IF (K% AND &8F)=&8D:PRINT "RIGHT";
320 IF (K% AND &8F)=&8E:PRINT "DOWN";
330 IF (K% AND &8F)=&8F:PRINT "UP";
340 PRINT
350 UNTIL FALSE

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Post Reply

Return to “general”