[comp.sys.acorn] Tiny Source - RISCOS system vars to read modifier keys

bdb@cl.cam.ac.uk (Brian Brunswick) (02/27/91)

I hope people don't mind a posting as small as this (40 lines),
but its something that I have found useful.

What it does is set up some system vars that read the state of
the modifier keys (shift, ctrl, alt, mouse buttons)
This is very useful to modify the behaviour of Obey scripts and
file run actions.

For instance, in my !boot sequence, I normally load in lots of
stuff, but sometimes its nice to not do so - it I want to run something
icompatible with it.

So I have a line which reads
If <ALT$KEY>=0 THEN Obey do-the-load-of-the-gunge-file
and can then disable all the extra stuff by holding down alt during
a boot. Another useful one is to change Obey files so that Alt-running
them edits, or BASIC programs to that ctrl-double clicking loads, or ...

Anyway, there follows the short basic program to set this up -
Hope its useful both as a utility and an example of m/c variables.
---------- cut --------
REM >KEYVAR
REM By Brian.Brunswick@uk.ac.cam.cl
asmlist=0
ON ERROR ON ERROR OFF:ERROR ERR,REPORT$+"(line "+STR$(ERL/10)+")"
DIM code 100
PROCKEYVAR("SHIFT$KEY",0)
PROCKEYVAR("CTRL$KEY",1)
PROCKEYVAR("ALT$KEY",2)
PROCKEYVAR("LEFT$KEY",9)
PROCKEYVAR("CENTRE$KEY",10)
PROCKEYVAR("RIGHT$KEY",11)
*Set Alias$@RunType_FEB IF |<ALT$KEY> THEN Desktop_Edit %*0 ELSE Obey %*0
END
:
DEF PROCKEYVAR(keyname$,keynum)
FOR pass=0 TO 2+asmlist STEP 2+asmlist
P%=code
[OPT pass
        B       write
.read
        STMFD   R13!,{R14}
        MOV     R0,#121
        MOV     R1,#keynum EOR &80
        SWI     "XOS_Byte"
        LDMVSFD R13!,{PC}
        CMP     R1,#0
        ADRNE   R0,val0
        ADREQ   R0,val1
        MOV     R2,#1
        LDMFD   R13!,{PC}
.write
        ADR     R0,errblk
        ORRS    PC,R14,#&10000000
.errblk
        DCD     0
        DCB     keyname$+" is read only"
        DCB     0
.val0   DCB     "1"
.val1   DCB     "0"
        ALIGN
]
NEXT
SYS "OS_SetVarVal",keyname$,code,P%-code,0,&10
ENDPROC
--------- cut -------
Brian.Brunswick@uk.ac.cam.cl  Disclaimer.  Short sig rules!