User Tools

Site Tools


copy_20key_20functionality_20with_20get_20and_20inkey

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
copy_20key_20functionality_20with_20get_20and_20inkey [2018/03/31 13:19] – external edit 127.0.0.1copy_20key_20functionality_20with_20get_20and_20inkey [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 1: Line 1:
 =====Copy Key functionality with GET and INKEY===== =====Copy Key functionality with GET and INKEY=====
  
-//by Richard Russell, April 2008//\\ \\  BBC BASIC for Windows emulates the [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin2.html#copyediting|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:\\ \\  +//by Richard Russell, April 2008//\\
-        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%<>+
-        IF copyF% PROCswap : PROCblob +
-        = K%+
  
-        DEF PROCswap +//BBC BASIC for Windows// and //BBC BASIC for SDL 2.0// emulate the [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin2.html#copyediting|Copy Key]] functionality provided on the BBC Microcomputer and other Acorn machinesbut 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 thatin 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).\\ \\  Occasionallyespecially 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 parameterbut with the Tab key acting as the Copy key:
-        LOCAL X%, Y% +
-        X% = POS Y% = VPOS +
-        SWAP X%copyX% : SWAP Y%copyY% +
-        PRINT TAB(X%,Y%)+
-        ENDPROC+
  
-        DEF PROCblob +<code bb4w>  
-        LOCAL rc{} +      DEF FNinkeycopy(T%) 
-        DIM rc{l%,t%,r%,b%} +      LOCAL K% 
-        rc.l% = @vdu%!48 +      PRIVATE copyX%, copyY%, copyF% 
-        rc.t% = @vdu%!52 +      IF copyF% PROCblob : PROCswap 
-        rc.r% = rc.l% + @vdu%!216 +      REPEAT 
-        rc.b% = rc.t% + @vdu%!220 +        K% = INKEY(T%) 
-        SYS "InvertRect", @memhdc%, rc{} +        CASE K% OF 
-        SYS "InvalidateRect", @hwnd%, rc{}, 0 +          WHEN 9: 
-        ENDPROC +            IF copyF% THEN 
-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:\\ \\  +              K% = GET(POS, VPOS) : VDU 9 
-        DEF FNgetcopy +            ELSE 
-        LOCAL K% +              copyX% = POS : copyY% = VPOS 
-        REPEAT +              copyF% = TRUE : PROCblob : K% = -1 
-          K% = FNinkeycopy(1) +            ENDIF 
-        UNTIL K%<>-1 +          WHEN 136,137,138,139: 
-        = K%+            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%<>
 +      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 
 +</code> 
 + 
 +In //BBC BASIC for SDL 2.0// replace **PROCblob** with the following code: 
 + 
 +<code bb4w> 
 +      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 
 +</code> 
 + 
 +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: 
 + 
 +<code bb4w> 
 +      DEF FNgetcopy 
 +      LOCAL K% 
 +      REPEAT 
 +        K% = FNinkeycopy(1) 
 +      UNTIL K%<>-1 
 +      = K% 
 +</code>
copy_20key_20functionality_20with_20get_20and_20inkey.1522502351.txt.gz · Last modified: 2024/01/05 00:18 (external edit)