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 emulates 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

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 for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
copy_20key_20functionality_20with_20get_20and_20inkey.txt · Last modified: 2018/04/16 10:46 by richardrussell