Re: How do U....

 BBS: Inland Empire Archive
Date: 07-01-92 (20:54)             Number: 1930
From: BOB SEWELL                   Refer#: NONE
  To: BREK WENDELN                  Recvd: NO  
Subj: Re: How do U....               Conf: (2) Quik_Bas
BW> I would like to know a line(s) of code that disable the following keys
BW> within a program:

    I'm not sure I can help with this, except that the old
INKEY$ routine seems to disable anything but Ctrl-Alt-Del.
However...

BW> I would also like to know how (in a line(s) of program code how to tell
BW> the computer in a statement to do something when a key combination is
BW> pressed -- like Alt-? and/or Alt-?-? & Ctrl-? and/or Ctrl-?-?

   This I can help you with. I know you'll get lots of
suggestions about using the ON KEY(x)/KEY(x) ON statements,
but I never liked that method for several reasons:
 1. you're limited to how many keys you can trap.  2. if a
trapped key-sequence is pressed, things can get screwy with
the     routine that was interrupted by the trap.
 3. I like to have more control over WHEN the program looks for and reacts
    to certain trapped keys, and the KEY(x) ON/KEY(x) OFF stuff gets
    confusing to me.

   So, what do I do? I just use the ol' INKEY$ function,
and look for keystrokes that have a length greater than
one, since function keys, arrow keys, two-stroke sequences
(such as Alt-C) and the editing keys (Home, Insert, etc.)
all return two bytes to INKEY$, with the first character a
zero. To find out what the second character in the INKEY$
return-string is, look in the manual for Keyboard Scan
Codes. (In my manual, it's in appendix D, page 339.) Find
which keys you want to trap in that list, then put that in
the code.

   For example, say you want to trap for Ctrl-C, Alt-X and
the Up Arrow. The following code will do this:

k$ = INKEY$
IF LEN(k$) > 1 THEN
   SELECT CASE ASC(k$)
      CASE 3              'trap Ctrl-C
         ...              'execute code for Ctrl-C
      CASE 45             'trap Alt-X
         ...              'execute code for Alt-X
      CASE 72             'trap up-arrow
         ...              'execute code for up-arrow
      ....                'other code, including CASE ELSE
   END SELECT
END IF

   The codes may be listed in the On-Line help, I don't
remember. If not, just write a small program to trap  input
as listed above, but print k$ to the screen. That'll show
the character representation of the code, i.e., Up Arrow
will display the letter 'H'.

   Hope this helps, Brek!

--- Echodor 3.11
 * Origin: Strawberry Fields - Nashville (1:116/5.0)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET