## Physical Device Driver Reference

[prev][next][parent][TOC]

### Type-Ahead Characters

An application can require the monitoring of all characters passing through a character device. In addition, the application can require that type- ahead characters are intercepted. Type-ahead characters are those keystrokes entered by a user after a program is started but before prompts for information are given. Monitor applications must do some additional work to intercept these keystrokes.

There is a time window between the time when an application is started and the time when the registration of the application's monitor is completed. During this time window, the application does not have access to the data stream. Because the monitor is not yet registered, it cannot intercept keystrokes. The physical device driver processes type-ahead keystrokes, placing them into its API buffer.

Note: If other applications have monitors registered with the monitor chain associated with the same data stream, type-ahead keystrokes will be filtered by these applications and returned to the device driver for processing. Registration of other monitor applications with the same monitor chain is irrelevant.

To monitor type-ahead characters, an application must:

1.Register its monitor

2.Read and save type-ahead characters from the API buffer after monitor registration is completed and before a call to DosMonRead is made

3.Play back the saved type-ahead characters and return them to the data stream by calling DosMonWrite

4.Monitor the data stream as usual, intercepting data from the data stream by calling DosMonRead and returning filtered data to the data stream by calling DosMonWrite

Pseudocode for monitoring type-ahead characters is illustrated in the following figure:

    --------------------------------------------------------------

                            The Application

    Description:  A single-threaded application that requires monitoring
      of all characters for a device, including type-ahead characters.

      CALL DosMonOpen to open the device and get a monitor handle for the device
      CALL DosSetPrty to set the priority of the monitor thread high
      CALL DosMonReg to register a monitor for the data stream of the device

    Before data is intercepted, get and save any type-ahead data
      that the physical device driver has processed before
      DosMonReg returned.

    WHILE the physical device driver's API buffer is not empty

      Get a character from the API buffer, using the appropriate
        device subsystem call
      Save the characters in a temporary buffer

    END WHILE

    Play back the type-ahead characters

    WHILE the temporary buffer is not empty

      Get a character from the temporary buffer
      Build a monitor record, according to the specifications of
        the physical device driver
      Filter the data
      CALL DosMonWrite to return it to the data stream and,
        therefore, to the device driver.  The physical device
        driver processes the data by placing it into its API
        buffer so that it can be received and processed by an application.

    END WHILE

    Monitor the data stream as usual.

    WHILE monitoring the data stream

      CALL DosMonRead to take a data record from the data stream
      Filter the data record
      CALL DosMonWrite to return the filtered data record to the data stream

    END WHILE

      CALL DosMonClose to remove the monitor buffers from the
        monitor chain and close the device handle
      Call DosExit to terminate this application.

    --------------------------------------------------------------