Messed around with it a little more and got it to work and return Caps
in b11 and Num in b10. I'm using b9 for timeout expired when using
INKEY rather than GET is an input method. I've had to hack in Caps and
Num-Lock status for the time being using an extra variable and
manually setting bits after the 32bit mask has been assembled. Both
Caps & Num-Lock state are actually the INVERSE of the bit values
returned after the call to OS_Byte 202 (Bit Clear = ON) for some
reason, so I'm checking the inverse and setting bits accordingly.
The other minor change was that JGH got the left and right mouse
buttons swapped. Starting at b12, it's Adjust, Menu, Select, not
Select, Menu, Adjust. I've included a verbose and hacky version of the
demo code that expands all 32 bits of the returned datastream into a
text string along with significance.
I've not bothered to use OS calls to convert the mask to a string,
just a variation of the debug code I posted the other day. The code
follows. It needs to be view in a fixed width font and as always,
sorry if the code wraps...
REM Demo code:
REPEAT
PRINT
A%=FNkeyb_scan
PRINT "Character: ";A% AND 511
PRINT "Modifiers: &";~A% AND &00FFFC00 :REM This mask is doesn't take
into account Num-Lock state in b10
PRINT " T C RRRLLL "
PRINT " ONaAMSACSACSACS"
PRINT " uupdneltfltfltf"
PRINT "<-char-->tmsjultlttlttlt<-scan->"
PRINT "--------------------------------"
PRINT FNkeyb_bits2txt(A%,31)
PRINT "Keypress: ";A% >>> 24
PRINT
UNTIL FALSE
REM FNkeyb_deepscan(<100th secs>) - waits for and returns a "deep"
keypress
REM
-----------------------------------------------------------------------
REM Returns: b00-b08 : Keypress character
REM b09 : Timeout flag (Set if timeout expired in INKEY
variant.)
REM b10-b11 : Toggle state modifier keys:
REM b10 : Num-Lock state
REM b11 : Caps-Lock state
REM b12-b23 : Momentary state modifier keys:
REM b12 : Right mouse button
REM b13 : Middle mouse button
REM b14 : Left mouse button
REM b15 : Right ALT key
REM b16 : Right CTRL key
REM b17 : Right SHIFT key
REM b18 : Left ALT key
REM b19 : Left CTRL key
REM b20 : Left SHIFT key
REM b21 : Either ALT key
REM b22 : Either CTRL key
REM b23 : Either SHIFT key
REM b24-b31 : Physical key pressed
REM 00000000 11100000000000 000000000
REM 76543210 32109876543210 876543210
REM physical modifier__keys character
REM 33222222 22221111111111 0 000000000
REM 10987654 32109876543210 9 876543210
DEFFNkeyb_deepscan(timeout%)
LOCAL char%,key%,shift%,void%,fl%,mask%
IF timeout%=0 THEN
char%=GET :REM Keypress character. (No
timeout)
ELSE
char%=INKEY(timeout%) :REM Keypress character.
(With timeout)
IF char%<0 THEN
char%=0:PROCkeyb_setbit(0,fl%) :REM Make char% 0 if negative
and set flag for later.
ENDIF
ENDIF
shift%=0
FOR key%=1 TO 12
shift%=(shift%<<1)OR(INKEY-key% AND 1) :REM Read all modifier keys
NEXT
SYS"OS_Byte",&CA,0,&FF TO void%,key% :REM OS_Byte (R0=&CA (202),
R1=0, R2=&FF (255)). Read keybd status.
shift%=(shift%<<1)
IF NOT FNkeyb_tstbit(2,key%) THEN PROCkeyb_setbit(1,fl%) :REM b2
Clear = Num-Lock ON.
IF NOT FNkeyb_tstbit(4,key%) THEN PROCkeyb_setbit(2,fl%) :REM b4
Clear = Caps-Lock ON.
SYS"OS_Byte",&7A TO void%,key% :REM OS_Byte (R0=&7A (122)).
Read physical keypress.
mask%=(char% OR (key%<<24) OR (shift%<<11))
IF FNkeyb_tstbit(0,fl%) THEN PROCkeyb_setbit(9,mask%) :REM If b0
set, INKEY timeout...
IF FNkeyb_tstbit(1,fl%) THEN PROCkeyb_setbit(10,mask%) :REM If b1
set, Num-Lock ON...
IF FNkeyb_tstbit(2,fl%) THEN PROCkeyb_setbit(11,mask%) :REM If b2
set, Caps-Lock ON...
=mask%
REM Calls keyb_deepscan() with no timeout and returns raw data...
DEFFNkeyb_scan
=FNkeyb_deepscan(0)
REM Returns TRUE if given bit is set in mask...
DEFFNkeyb_tstbit(p%,m%)
=((m% AND 1<<p%)=(1<<p%))
REM Sets a given bit in a bitmask...
DEFPROCkeyb_setbit(p%,RETURN m%)
m%=m% OR (1<<p%)
ENDPROC
REM Build a text representation of a binary number... (Debug only.)
DEFFNkeyb_bits2txt(mask%,len%)
LOCAL i%,bits$
FOR i%=0 TO len%
IF FNkeyb_tstbit(i%,mask%) THEN bits$+="1" ELSE bits$+="0"
NEXT
=bits$
Yes... I know it's not the most elegant solution, but it does the job.
If someone would like the challenge of tidying it up a bit then go
ahead, and post it on here afterwards... lol
Many thanks for all your help