ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
DEF SEG Statement, POKE Statement and PEEK Function Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses the DEF SEG statement, the PEEK function, and POKE
' statement to turn the Caps Lock key on and off. The program uses the
' LINE INPUT statement to prompt the user to enter a string, demonstrating
' that the Caps Lock key is on.
 
' Note: This program contains hardware-specific instructions. It works
' correctly on IBM PC, XT, and AT computers.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 DECLARE SUB CapsOn ()
 DECLARE SUB CapsOff ()
 DECLARE SUB PrntMsg (R%, C%, M$)
 
 CLS                              ' Clear the screen
 CapsOn
 PrntMsg 24, 1, "<Caps Lock On>"
 LOCATE 12, 10
 LINE INPUT "Enter a string (all characters are caps): ", S$
 CapsOff
 PrntMsg 24, 1, "              "
 PrntMsg 25, 1, "Press any key to continue..."
 DO WHILE INKEY$ = "": LOOP
 CLS                              ' Clear the screen
 END
 
 STATIC SUB CapsOff ()            ' Turn Caps Lock off
   DEF SEG = 0
   ' Set Caps Lock off (turn off bit 6 of &H0417).
   POKE &H417, PEEK(&H417) AND &HBF
   DEF SEG
 END SUB
 
 STATIC SUB CapsOn ()             ' Turn Caps Lock on
   ' Set segment to low memory.
   DEF SEG = 0
   ' Set Caps Lock on (turn on bit 6 of &H0417).
   POKE &H417, PEEK(&H417) OR &H40
   ' Restore segment.
   DEF SEG
 END SUB
 
 STATIC SUB PrntMsg (Row%, Col%, Message$)
    ' Print message at Row%, Col% without changing cursor.
    ' Save cursor position.
    CurRow% = CSRLIN: CurCol% = POS(0)
    LOCATE Row%, Col%: PRINT Message$;
    ' Restore cursor.
    LOCATE CurRow%, CurCol%
 END SUB