User Tools

Site Tools


copy_20key_20functionality_20with_20get_20and_20inkey

Copy Key functionality with GET and INKEY

by Richard Russell, April 2008

BBC BASIC for Windows and BBC BASIC for SDL 2.0 emulate the Copy Key functionality provided on the BBC Microcomputer and other Acorn machines, but only at the Immediate Mode prompt or when user input is being requested using the INPUT statement; Copy Key editing is not available when the keyboard is read using GET or INKEY. The main reason for this limitation is that, in the absence of a dedicated Copy key, the Tab key is used instead to initiate the Copy operation. When GET or INKEY is used, the Tab key returns its normal ASCII value (9).

Occasionally, especially when porting a program from an Acorn platform, it might be convenient for Copy Key editing to be available when using GET or INKEY. The code below provides this capability, by means of the user-defined function FNinkeycopy. This emulates the INKEY function (with a zero or positive parameter) but with the Tab key acting as the Copy key:

      DEF FNinkeycopy(T%)
      LOCAL K%
      PRIVATE copyX%, copyY%, copyF%
      IF copyF% PROCblob : PROCswap
      REPEAT
        K% = INKEY(T%)
        CASE K% OF
          WHEN 9:
            IF copyF% THEN
              K% = GET(POS, VPOS) : VDU 9
            ELSE
              copyX% = POS : copyY% = VPOS
              copyF% = TRUE : PROCblob : K% = -1
            ENDIF
          WHEN 136,137,138,139:
            IF copyF% VDU K% AND &7F : K% = -1
          WHEN 13, 155:
            IF copyF% THEN
              IF K% = 155 K% = -1
              copyF% = FALSE : PROCswap : PROCblob
            ENDIF
        ENDCASE
      UNTIL K%<>9
      IF copyF% PROCswap : PROCblob
      = K%
 
      DEF PROCswap
      LOCAL X%, Y%
      X% = POS : Y% = VPOS
      SWAP X%, copyX% : SWAP Y%, copyY%
      PRINT TAB(X%,Y%);
      ENDPROC
 
      DEF PROCblob
      LOCAL rc{}
      DIM rc{l%,t%,r%,b%}
      rc.l% = @vdu%!48
      rc.t% = @vdu%!52
      rc.r% = rc.l% + @vdu%!216
      rc.b% = rc.t% + @vdu%!220
      SYS "InvertRect", @memhdc%, rc{}
      SYS "InvalidateRect", @hwnd%, rc{}, 0
      ENDPROC

In BBC BASIC for SDL 2.0 replace PROCblob with the following code:

      DEF PROCblob
      LOCAL rc{} : PRIVATE B%
      IF B% = 0 SYS "SDL_ComposeCustomBlendMode", 8, 4, 1, 1, 2, 1 TO B%
      DIM rc{x%,y%,w%,h%}
      SYS "SDL_SetRenderDrawBlendMode", @memhdc%, B%
      SYS "SDL_SetRenderDrawColor", @memhdc%, &FF, &FF, &FF, &FF
      rc.x% = @vdu%!48  : rc.y% = @vdu%!52
      rc.w% = @vdu%!216 : rc.h% = @vdu%!220
      SYS "SDL_RenderFillRect", @memhdc%, rc{}
      SYS "SDL_SetRenderDrawBlendMode", @memhdc%, 1
      ENDPROC

Note that, just as in the case of Immediate Mode and the INPUT statement, Copy editing must be initiated by first pressing Tab. This differs slightly from the way it works on machines having a dedicated Copy key. Copy editing mode is terminated when Enter is pressed, or explicitly by pressing Shift+Tab.

To emulate GET, with Copy Key editing, you can use the following function:

      DEF FNgetcopy
      LOCAL K%
      REPEAT
        K% = FNinkeycopy(1)
      UNTIL K%<>-1
      = K%
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
copy_20key_20functionality_20with_20get_20and_20inkey.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1