BBC BASIC
Programming >> User Interface >> Improving efficiency and retrieving a key
http://bbcbasic.conforums.com/index.cgi?board=ui&action=display&num=1502761890

Improving efficiency and retrieving a key
Post by michael on Aug 15th, 2017, 01:51am

This is a VERY efficient way to manage input from the keyboard, yet also keep the CPU cool

This modification is an expansion of Raspberry Pi topic which is greatly dependent on Richards solution,

It is highly valuable on BBCSDL and BBC4W ...



Code:
      k%=0:resp%=0
      what%=0
      REM This section gives a keypressed value that can be stored to a string

      REPEAT
        WAIT 1
        what%=FNkeychk
        IF what%>0 THEN PRINT STR$(what%)+"  "+CHR$(what%)
      UNTIL FALSE
      END
      REM keep FNkeychk and FNmoucheck together
      REM ****************************************************************
      DEFFNkeychk
      REPEAT
        k% = INKEY(4)
        resp%=FNmoucheck
      UNTIL k%<>-1 OR resp% >0
      =k%
      DEF FNmoucheck
      PRIVATE mx%,my%,mb%,x%,y%,b%
      MOUSE x%,y%,b%
      IF mx%=0 AND my%=0 AND mb%=0 THEN mx%=x%:my%=y%:mb%=b%: =-1
      IF mx%=x% AND my%=y% AND mb%=b% THEN =-1 ELSE mx%=x%:my%=y%:mb%=b%:=1
      REM ********* END OF EFFICIENT CONTROLS  ****************************