NextKey()

NEXTKEY()

Get the next key code in the buffer without extracting it.

Syntax

      NEXTKEY( [<nInputMask>] ) --> nKey

Arguments

nInputMask is an optional integer value composed of one or more INKEY_ or HB_INKEY_ constants. The sole purpose of this argument is to allow switching between using HB_INKEY_EXTENDED key codes and using the normal CA-Cl*pper-compatible key codes

Returns

<nKey> The value of the next key in the Harbour keyboard buffer.

Description

Returns the value of the next key in the Harbour keyboard buffer without extracting it.

Examples

      // Use NEXTKEY() with INKEY() to change display characters, or by
      // itself to exit the loop, so that the caller can detect the Esc.
      LOCAL nKey, cChar := "+"
      DO WHILE .T.
         ?? cChar
         nKey := NextKey()
         IF nKey == K_ESC
            EXIT
         ELSE
            IF nKey != 0
               cChar := Chr( nKey )
            ENDIF
         ENDIF
      ENDDO

Tests

      KEYBOARD "AB"; ? NEXTKEY(), NEXTKEY() ==>   65   65

Compliance

NEXTKEY() is compliant with CA-Cl*pper 5.3, but has been extended for Harbour.

Files

Library is rtl

Seealso

INKEY(), LASTKEY()

LastKey()

LASTKEY()

Get the last key extracted from the keyboard buffer.

Syntax

      LASTKEY( [<nInputMask>] ) --> nKey

Arguments

nInputMask is an optional integer value composed of one or more INKEY_ or HB_INKEY_ constants. The sole purpose of this argument is to allow switching between using HB_INKEY_EXTENDED key codes and using the normal CA-Cl*pper-compatible key codes

Returns

<nKey> The last key extracted from the keyboard buffer.

Description

Returns the value of the last key exttracted from the Harbour keyboard buffer

Examples

      // Continue looping unless the ESC key was pressed in MainFunc()
      DO WHILE .T.
         MainFunc()
         IF LastKey() == K_ESC
            EXIT
         ENDIF
      ENDDO

Tests

      KEYBOARD "AB"; ? INKEY(), LASTKEY() ==>   65   65

Compliance

LASTKEY() is compliant with CA-Cl*pper 5.3, but has been extended for Harbour.

Files

Library is rtl

Seealso

INKEY(), LASTKEY()

Inkey()

INKEY()

Extracts the next key code from the Harbour keyboard buffer.

Syntax

      INKEY( [<nTimeout>] [,<nEvents>] ) --> nKey

Arguments

<nTimeout> is an optional timeout value in seconds, with a granularity of 1/10th of a second. If omitted, INKEY() returns immediately. If set to 0, INKEY() waits until an input event occurs. If set to any other value, INKEY() will return either when an input event occurs or when the timeout period has elapsed. If only this parameter is specified and it is not numeric, it will be treated as if it were 0. But if both parameters are specified and this parameter is not numeric, it will be treated as if it were not present.

<nEvents> is an optional mask of input events that are to be enabled. If omitted, defaults to hb_set.HB_SET_EVENTMASK. Valid input masks are in inkey.ch and are explained below. It is recommended that the mask names be used rather than their numeric values, in case the numeric values change in future releases of Harbour. To allow more than one type of input event, simply add the various mask names together.

        inkey.ch            Meaning
        ------------------  ------------------------------------------------
        INKEY_MOVE          Mouse motion events are allowed
        INKEY_LDOWN         The mouse left click down event is allowed
        INKEY_LUP           The mouse left click up event is allowed
        INKEY_RDOWN         The mouse right click down event is allowed
        INKEY_RUP           The mouse right click up event is allowed
        INKEY_KEYBOARD      All keyboard events are allowed
        INKEY_ALL           All mouse and keyboard events are allowed
        HB_INKEY_EXTENDED   Extended keyboard codes are used.

If the parameter is not numeric, it will be treated as if it were set to hb_set.HB_SET_EVENTMASK.

Returns

0 in case of timeout with no input event, otherwise returns a value in the range -47 to 386 for keyboard events or the range 1001 to 1007 for mouse events. Mouse events and non-printable keyboard events are represented by the K_<event> values listed in inkey.ch. Keyboard event return codes in the range 32 through 127 are equivalent to the printable ASCII character set. Keyboard event return codes in the range 128 through 255 are assumed to be printable, but results may vary based on hardware and nationality. If HB_INKEY_EXTENDED mode is used, then the return value for keyboard events ranges from 1 through 767 and 1077 through 1491, although not all codes are used.

Extended key codes consist of the PC keyboard scan code and one or more offset values. If no keyboard modifier was used, then HB_INKEY_NONE is added. The Alt key adds HB_INKEY_ALT, the Ctrl key adds HB_INKEY_CTRL, the Shift key adds HB_INKEY_SHIFT, and enhanced keys (KeyPad+/ and CursorPad keys) add HB_INKEY_ENHANCED. For example, F1 is scan code 59, so if you just press F1, you get key code 315, but Alt+F1 gives 443, Ctrl+F1 gives 571, and Shift+ F1 gives 699. And NumPad+/ gives 1077, 1205, 1333, and 1461. At this time, the only value that can combine with other values is HB_INKEY_ENHANCED (i.e., there are no Alt+Ctl combinations, etc.)

Note: The extended key code set is larger than the normal key code set. As a result, if you switch between the normal and extended modes, you need to be aware that some codes get translated into a zero in normal mode (because there is no corresponding code in normal mode) and that these codes get removed from the keyboard input buffer in normal mode and you won’t be able to go back and fetch them later in extended mode.

Description

INKEY() can be used to detect input events, such as keypress, mouse movement, or mouse key clicks (up and/or down).

Examples

      // Wait for the user to press the Esc key
      ? "Please press the ESC key."
      DO WHILE Inkey( 0.1 ) != K_ESC
      ENDDO

Tests

      KEYBOARD "AB"; ? Inkey(), Inkey() ==>   65   66

Compliance

INKEY() is compliant with the CA-Cl*pper 5.3 INKEY() function with one exception: The Harbour INKEY() function will raise an argument error if the first parameter is less than or equal to 0 and the second parameter (or the default mask) is not valid, because otherwise INKEY would never return, because it was, in effect, asked to wait forever for no events (Note: In CA-Cl*pper, this also blocks SET KEY events).

Files

Library is rtl

Seealso

inkey.ch

hb_keyPut()

HB_KEYPUT()

Put an inkey code to the keyboard buffer.

Syntax

      HB_KEYPUT( <nInkeyCode> )

Arguments

<nInkeyCode> is the inkey code, which should be inserted into the keyboard buffer.

Returns

There is no return value.

Description

Inserts an inkey code to the string buffer. The buffer is *not* cleared in this operation. This function allows to insert such inkey codes which are not in the range of 0 to 255. To insert more than one code, call the function repeatedly. The zero code cannot be inserted.

Examples

      // Stuff an Alt+PgDn key into the keyboard buffer
      hb_keyPut( K_ALT_PGDN )

Tests

      hb_keyPut( K_ALT_PGDN ) ; ? INKEY() ==> 417
      hb_keyPut( K_F11 ) ; ? INKEY() ==> -40

Compliance

Harbour

Files

Library is rtl

Seealso

KEYBOARD, CLEAR TYPEAHEAD, INKEY()

SP_SHIFTY

 SHIFTY() Determines shift key settings

 Returns
 <lOn> => indicated shift key is on/off

 Syntax
 SHIFTY(nKey)

 Description
 Determines shift key settings for the keyboard shift
 keys, based on <nKey>:

    1     Right shift key
    2     Left shift key
    3     Ctrl key
    4     Alt key
    5     Scroll lock key
    6     Number lock key
    7     Caps lock key
    8     Insert key

 Examples
  do while .t.

    if inkey()=27
      exit
    endif

    @0,0 SAY "Rshift      "
    ??shifty(1)
    @1,0 SAY "Lshift      "
    ??shifty(2)
    @2,0 SAY "Ctrl        "
    ??shifty(3)
    @3,0 SAY "Alt         "
    ??shifty(4)
    @4,0 SAY "Scroll      "
    ??shifty(5)
    @5,0 SAY "Numlock     "
    ??shifty(6)
    @6,0 SAY "Capslock    "
    ??shifty(7)
    @7,0 SAY "Insert      "
    ??shifty(8)
  enddo

 Source: S_SHIFT.ASM

SP_RAT_EVENT

RAT_EVENT()

  Short:
  ------
  RAT_EVENT() Event handler - inkey() with mouse awareness

  Returns:
  --------
  <nEvent> => Event value - either inkey() value or
  mouse value

  Syntax:
  -------
  RAT_EVENT([nTimeout],[lClearkb])

  Description:
  ------------
  Event handler - inkey() with mouse awareness

  <nTimeout>   is the   # seconds to wait before
  timeout. Zero (0) means indefinately . If you don't pass
  anything, default is 0. Slight difference from inkey() there.

  Returns values are:

     If keystroke                                   inkey() value
     If left mouse button has been depressed        K_MOUSELEFT
     If right mouse button has been depressed       500
     If timeout                                      0

  [lClearkb]   optional clear keyboard True (default)
  or False. If a keystroke is gotten, and this is True, clear the
  keyboard with:
                     while inkey()#0
                     end

  Examples:
  ---------
   e := 0

   while  e#27
      e := rat_event(30)
      do case
      case e == 0
        ? "Timed out after 30 seconds"
      case e < 400
        ? "Key press with inkey() value of :",e
      case e == 400
        ? "Left mouse button pressed at :"
        ?? "row-> ",rat_eqmrow(),  "col-> ",rat_eqmcol()
      case e == 500
        ? "Right mouse button pressed at :"
        ?? "row-> ",rat_eqmrow(),  "col-> ",rat_eqmcol()
      endcase
   end

  Source:
  -------
  S_MOOSE.PRG

See Also : INKEY(), RAT_ELBHD(), RAT_EQMCOL(), RAT_EQMROW(), RAT_ERBHD(), 
           RAT_ISMOUSE(), RAT_LASTEV(), RAT_MENU2(), RAT_READ()

SP_ABORT

ABORT()

  Short:
  ------
  ABORT() Pops up dialog box asking: Abort  Don't Abort

  Returns:
  --------
  <lDoAbort> => True or False

  Syntax:
  -------
  ABORT([cColor],[nTop,nLeft,nBottom,nRight])

  Description:
  ------------
  Tests for escape key press at last wait state. If
  escape key was pressed, pops up a dialog box asking
      [Abort] [Don't Abort]

  Returns True if [Abort], False if [Don't Abort] or
  False if last key was not 27 (escape key).

  Box color is sls_popmenu() or optionally [cColor].
  Box dimensions are: 9,29,13,51 or optionally
  [nTop,nLeft,nBottom,nRight]

  Examples:
  ---------
   INKEY(0)
   IF ABORT()  // test for lastkey() = 27
       exit
   ENDIF

  Source:
  -------
  S_ABORT.PRG

 

SP_AASKIP

AASKIP()

  Short:
  ------
  AASKIP() Use for skipblock for arrays in Tbrowse

  Returns:
  --------
  <nSkipcount> => number skipped, forward or backward

  Syntax:
  -------
  AASKIP(nSkip,@nElement,nMaxRows)

  Description:
  ------------
  Use this to create the SKIPBLOCK for a tbrowse that browses
  an array, as in :

    aTbrowseObject:SKIPBLOCK := {|n|aaskip(n,@nElement,len(aArray)}

  <nSkip>      is passed in by Tbrowse as a +- value, or
               as zero.

  <nElement>   is the current array element number.
               PASSED IN BY REFERENCE!

  <nMaxrows>   refers to the length of the array being
               browsed

  Examples:
  ---------
  // this example browses the fields in a database

   local nLastKey,  nElement    := 1
   local aArray := dbstruct()
   local oTb        := tBrowseNew(2,2,20,78)
   oTb:addcolumn(tbcolumnew("Name",{||aArray[nElement,1]}))
   oTb:addcolumn(tbcolumnew("Type", {||aArray[nElement,2]}))
   oTb:addcolumn(tbcolumnew("Len " , {||aArray[nElement,3]}))
   oTb:addcolumn(tbcolumnew("Deci",  {||aArray[nElement,4]}))
   oTb:Skipblock        := {|n|aaskip(n,@nElement,len(aArray)}
   oTb:goTopBlock       := {||nElement := 1}
   oTb:goBottomBlock    := {||nElement := len(aArray)}

   while .t.
     while !oTb:stabilize()
     end
     nLastKey := inkey(0)
     do case
        /// various actions.....
     endcase
   end

  Notes:
  -------
  Aaskip() is used by a lot of SuperLib functions, but
  is very useful by itself for creating array tbrowses.

  Source:
  -------
  S_AASKIP.PRG

 

 

C5 UI General

 

C5 UI General :

CLEAR TYPEAHEAD :

Empty the keyboard buffer

CLEAR TYPEAHEAD

INKEY() :

Extract a character from the keyboard buffer

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

KEYBOARD :

Stuff a string into the keyboard buffer

KEYBOARD <cString>

LASTKEY() :

Return the INKEY() value of the last key in the buffer

LASTKEY() --> nInkeyCode

NEXTKEY() :

Read the pending key in the keyboard buffer

NEXTKEY() --> nInkeyCode

SET TYPEAHEAD :

Set the size of the keyboard buffer

SET TYPEAHEAD TO <nKeyboardSize>

 

 

C5_INKEY

 INKEY()
 Extract a character from the keyboard buffer or a mouse event
------------------------------------------------------------------------------
 Syntax

     INKEY([<nSeconds>] [,<nEventMask>]) --> nInkeyCode

 Arguments

     <nSeconds> specifies the number of seconds INKEY() waits for a
     keypress or mouse event.  You can specify the value in increments as
     small as one-tenth of a second.  Specifying zero halts the program until
     a key is pressed or an unmasked event occurs.  If <nSeconds> is omitted,
     INKEY() does not wait for a keypress or mouse event.

     <nEventMask> specifies which events should be returned.  If
     <nEventMask> is omitted, the value represented by the
     SET EVENTMASK command will be used.  If there is no
     SET EVENTMASK command issued, the default value that will be used is 128
     (keyboard events only).

     This parameter can be any combination of the following values.  The
     constant values listed below are defined in Inkey.ch.

     Inkey Constants
     ------------------------------------------------------------------------
     Constant       Value     Descripiton
     ------------------------------------------------------------------------
     INKEY_MOVE     1         Mouse Events
     INKEY_LDOWN    2         Mouse Left Click Down
     INKEY_LUP      4         Mouse Left Click Up
     INKEY_RDOWN    8         Mouse Right Click Down
     INKEY_RUP      16        Mouse Right Click Up
     INKEY_KEYBOARD 128       Keyboard Events
     INKEY_ALL      159       All Mouse and Keyboard Events
     ------------------------------------------------------------------------

 Returns

     INKEY() returns an integer value from -39 to 386 for keyboard events and
     integer values from 1001 to 1007 for mouse events.  This value
     identifies either the key extracted from the keyboard buffer or the
     mouse event that last occurred.  If the keyboard buffer is empty, and no
     mouse events are taking place, INKEY() returns 0.  INKEY() returns
     values for all ASCII characters, function, Alt+Function, Ctrl+Function,
     Alt+Letter, and Ctrl+Letter key combinations.

 Description

     INKEY() is a keyboard function that extracts the next key pending in the
     keyboard buffer or the next mouse event and returns a value representing
     the appropriate event.  The value is also saved internally and can be
     accessed using LASTKEY().  If the <nSeconds> argument is specified and
     there are no pending keys in the buffer, program execution pauses until
     a key appears in the keyboard buffer, or an appropriate mouse event
     occurs, or <nSeconds> has elapsed.  The time INKEY() 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
     pressed or an unmasked mouse event occurs.  Note that INKEY() is not a
     wait state and, therefore, SET KEYs are not active.

     INKEY() is similar to the NEXTKEY() function.  Unlike INKEY(), however,
     NEXTKEY() reads, but does not extract the key or mouse event.  This is
     useful when you need to test for a key or mouse event without processing
     it.

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

 Examples

     .  The following example will inform INKEY() to terminate if the
        left mouse button has been clicked or the right mouse button has been
        clicked.  If no events of this type occur within 10 seconds, INKEY()
        will terminate.

        ? INKEY( 10 , INKEY_LDOWN + INKEY_RDOWN )