[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 InterruptKey()
 Extract a character from the keyboard buffer.
-------------------------------------------------------------------------------

 Syntax:

     InterruptKey( [<nSeconds>] ) --> nInkeyCode

 Arguments:

     <nSeconds> specifies the number of seconds InterruptKey() waits
     for a keypress.  The value can be specified in increments as small as
     one-tenth of a second.  Specifying zero halts the program until a key
     is pressed.  If <nSeconds> is omitted, InterruptKey() does not wait
     for a keypress.

 Returns:

     InterruptKey() returns an integer numeric value from -42 to 386,
     identifying the key extracted from the keyboard buffer.  If the
     keyboard buffer is empty, InterruptKey() returns zero.  InterruptKey()
     returns values for all ASCII characters, function, Alt-function,
     Ctrl-function, Alt-letter, Ctrl-letter key, and mouse key combinations.

 Description:

     InterruptKey() is a keyboard function that extracts the next key
     pending in the keyboard buffer and returns a value which represents
     the key.  The codeblock specified in the SetInterrupt() function is
     processed while waiting for a key press or mouse interrupt.  The value
     is also saved internally and can be accessed using LastInkey().  If
     the <nSeconds> argument is specified and there are no pending keys or
     mouse interrupts in the buffer, program execution pauses until a key
     appears in the keyboard buffer, or <nSeconds> has elapsed.  The time
     InterruptKey() waits is based on the operating system clock and is not
     related to the microprocessor speed.  If <nSeconds> is zero, program
     execution pauses until a key is placed into the buffer.  Note that
     InterruptKey() is not a wait state and therefore SET KEYs are not
     active.

     InterruptKey() is similar to the NEXTKEY() function.  Unlike,
     InterruptKey(), however, NEXTKEY() reads but does not extract the key
     from the keyboard buffer.  This is useful when you need to test for a
     key without processing it, however, NEXTKEY() does not check for
     mouse input.

     InterruptKey() is the basic primitive of the Clipper system for
     fetching keys from the keyboard buffer.  It is used for polling the
     keyboard or pausing program execution to wait for a keypress.  As an
     example, you can use InterruptKey() to terminate commands with a
     record scope such as LIST, LABEL FORM, and REPORT FORM by including it
     in a WHILE condition.  Refer to the example below.

     A list of key values is as follows:


           // Mouse keys
           M_LEFT_BUTTON    -48    // Left button
           M_RIGHT_BUTTON   -49    // Right button
           M_MIDDLE_BUTTON  -50    // Middle button
           M_DOUBLE_CLICK   -51    // Double Left button


           // Cursor movement keys
           K_UP            5       // Uparrow, Ctrl-E
           K_DOWN          24      // Dnarrow, Ctrl-X
           K_LEFT          19      // Leftarrow, Ctrl-S
           K_RIGHT         4       // Rightarrow, Ctrl-D
           K_HOME          1       // Home, Ctrl-A
           K_END           6       // End, Ctrl-F
           K_PGUP          18      // PgUp, Ctrl-R
           K_PGDN          3       // PgDn, Ctrl-C
           K_CTRL_LEFT     26      // Ctrl-Leftarrow, Ctrl-Z
           K_CTRL_RIGHT    2       // Ctrl-Rightarrow, Ctrl-B
           K_CTRL_HOME     29      // Ctrl-Home, Ctrl-]
           K_CTRL_END      23      // Ctrl-End, Ctrl-W
           K_CTRL_PGUP     31      // Ctrl-PgUp, Ctrl-Hyphen
           K_CTRL_PGDN     30      // Ctrl-PgDn, Ctrl-
           K_CTRL_RET      10      // Ctrl-Return

           K_ESC           27      // Esc, Ctrl-[
           K_RETURN        13      // Return, Ctrl-M
           K_ENTER         13      // Enter, Ctrl-M


           // Editing keys
           K_INS           22      // Ins, Ctrl-V
           K_DEL           7       // Del, Ctrl-G
           K_BS            8       // Backspace, Ctrl-H
           K_CTRL_BS       127     // Ctrl-Backspace
           K_TAB           9       // Tab, Ctrl-I
           K_SH_TAB        271     // Shift-Tab


           // Control keys
           K_CTRL_A        1       // Ctrl-A, Home
           K_CTRL_B        2       // Ctrl-B, Ctrl-Rightarrow
           K_CTRL_C        3       // Ctrl-C, PgDn, Ctrl-ScrollLock
           K_CTRL_D        4       // Ctrl-D, Rightarrow
           K_CTRL_E        5       // Ctrl-E, Uparrow
           K_CTRL_F        6       // Ctrl-F, End
           K_CTRL_G        7       // Ctrl-G, Del
           K_CTRL_H        8       // Ctrl-H, Backspace
           K_CTRL_I        9       // Ctrl-I, Tab
           K_CTRL_J        10      // Ctrl-J
           K_CTRL_K        11      // Ctrl-K
           K_CTRL_L        12      // Ctrl-L
           K_CTRL_M        13      // Ctrl-M, Return
           K_CTRL_N        14      // Ctrl-N
           K_CTRL_O        15      // Ctrl-O
           K_CTRL_P        16      // Ctrl-P
           K_CTRL_Q        17      // Ctrl-Q
           K_CTRL_R        18      // Ctrl-R, PgUp
           K_CTRL_S        19      // Ctrl-S, Leftarrow
           K_CTRL_T        20      // Ctrl-T
           K_CTRL_U        21      // Ctrl-U
           K_CTRL_V        22      // Ctrl-V, Ins
           K_CTRL_W        23      // Ctrl-W, Ctrl-End
           K_CTRL_X        24      // Ctrl-X, Dnarrow
           K_CTRL_Y        25      // Ctrl-Y
           K_CTRL_Z        26      // Ctrl-Z, Ctrl-Leftarrow


           // Alt keys
           K_ALT_A         286     // Alt-A
           K_ALT_B         304     // Alt-B
           K_ALT_C         302     // Alt-C
           K_ALT_D         288     // Alt-D
           K_ALT_E         274     // Alt-E
           K_ALT_F         289     // Alt-F
           K_ALT_G         290     // Alt-G
           K_ALT_H         291     // Alt-H
           K_ALT_I         279     // Alt-I
           K_ALT_J         292     // Alt-J
           K_ALT_K         293     // Alt-K
           K_ALT_L         294     // Alt-L
           K_ALT_M         306     // Alt-M
           K_ALT_N         305     // Alt-N
           K_ALT_O         280     // Alt-O
           K_ALT_P         281     // Alt-P
           K_ALT_Q         272     // Alt-Q
           K_ALT_R         275     // Alt-R
           K_ALT_S         287     // Alt-S
           K_ALT_T         276     // Alt-T
           K_ALT_U         278     // Alt-U
           K_ALT_V         303     // Alt-V
           K_ALT_W         273     // Alt-W
           K_ALT_X         301     // Alt-X
           K_ALT_Y         277     // Alt-Y
           K_ALT_Z         300     // Alt-Z
           K_ALT_1         376     // Alt-1
           K_ALT_2         377     // Alt-2
           K_ALT_3         378     // Alt-3
           K_ALT_4         379     // Alt-4
           K_ALT_5         380     // Alt-5
           K_ALT_6         381     // Alt-6
           K_ALT_7         382     // Alt-7
           K_ALT_8         383     // Alt-8
           K_ALT_9         384     // Alt-9
           K_ALT_0         385     // Alt-0


           // Function keys
           K_F1            28      // F1, Ctrl-\
           K_F2            -1      // F2
           K_F3            -2      // F3
           K_F4            -3      // F4
           K_F5            -4      // F5
           K_F6            -5      // F6
           K_F7            -6      // F7
           K_F8            -7      // F8
           K_F9            -8      // F9
           K_F10           -9      // F10
           K_F11           -40     // F11
           K_F12           -41     // F12


           // Control-function keys
           K_CTRL_F1       -20     // Ctrl-F1
           K_CTRL_F2       -21     // Ctrl-F2
           K_CTRL_F3       -22     // Ctrl-F4
           K_CTRL_F4       -23     // Ctrl-F3
           K_CTRL_F5       -24     // Ctrl-F5
           K_CTRL_F6       -25     // Ctrl-F6
           K_CTRL_F7       -26     // Ctrl-F7
           K_CTRL_F8       -27     // Ctrl-F8
           K_CTRL_F9       -28     // Ctrl-F9
           K_CTRL_F10      -29     // Ctrl-F10
           K_CTRL_F11      -44     // Ctrl-F11
           K_CTRL_F12      -45     // Ctrl-F12


           // Alt-function keys
           K_ALT_F1        -30     // Alt-F1
           K_ALT_F2        -31     // Alt-F2
           K_ALT_F3        -32     // Alt-F3
           K_ALT_F4        -33     // Alt-F4
           K_ALT_F5        -34     // Alt-F5
           K_ALT_F6        -35     // Alt-F6
           K_ALT_F7        -36     // Alt-F7
           K_ALT_F8        -37     // Alt-F8
           K_ALT_F9        -38     // Alt-F9
           K_ALT_F10       -39     // Alt-F10
           K_ALT_F11       -46     // Alt-F11
           K_ALT_F12       -47     // Alt-F12


           // Shift-function keys
           K_SH_F1         -10     // Shift-F1
           K_SH_F2         -11     // Shift-F2
           K_SH_F3         -12     // Shift-F3
           K_SH_F4         -13     // Shift-F4
           K_SH_F5         -14     // Shift-F5
           K_SH_F6         -15     // Shift-F6
           K_SH_F7         -16     // Shift-F7
           K_SH_F8         -17     // Shift-F8
           K_SH_F9         -18     // Shift-F9
           K_SH_F10        -19     // Shift-F10
           K_SH_F11        -42     // Shift-F11
           K_SH_F12        -43     // Shift-F12

 Examples:

     .  The following example gets a key from the keyboard and then displays
        the character value of the key followed by the InterruptKey() value:

        #include "Inkey.ch"
        //
        LOCAL nInkeyCode := 0
        DO WHILE LastInkey() != K_ESC
           ? "Press any key: "
           nInkeyCode := InterruptKey( 0 )
           ?? "Character:", CHR(nInkeyCode),;
              "InterruptKey() code:", LTRIM(STR(nInkeyCode))
        ENDDO
        RETURN

     .  This example uses InterruptKey() to poll for a user interrupt
        keypress during a REPORT FORM.  If the user presses Esc during the
        printing process, the REPORT FORM terminates:

        #include "Inkey.ch"
        //
        USE Sales INDEX Salesman NEW
        REPORT FORM Monthly FOR MONTH(SalesDate) = MONTH(DATE());
           WHILE InterruptKey() != K_ESC


 Files:  Library is CUACLIP.LIB, header file is Inkey.ch and CUACLIP.CH.

See Also: Interrupt() LastInkey() SetInterrupt() EX2.PRG
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson