Recording Keystrokes

February 1, 1996

Author: Tim McCormley
Date: 2/1/96
Category: Programming Tip
Keywords: keystroke-recording
Summary: Acucobol has a special library routine, "W$KEYBUF", which can be used to record keystrokes. This can be useful for building test environments or as scripts for setting up batch jobs to run overnight.

See the attached COBOL program for an example of how the "W$KEYBUF" routine might be used. The program is intended to be called as a hot-key program, and so should not require any coding changes to your existing application. Instructions for use:

        1) Modify the cblconfig file to assign a key to execute the
         recorder.
        2) When the recorder window is displayed, select "R" (Record),
         "P" (Playback), or "S" (Stop Recording).  You may press "Esc"
         to cancel the current operation.

The program writes out a sequential file that is designated by the user. This file may later be edited if necessary. Because the user must hit a key to pop-up the controlling window, the key designated as the "activation key" (the hot-key designated to start the the recorder) is saved to the sequential file along with all the other keystrokes typed by the user. This key must be removed from the destination file manually.

identification division.
program-id. testit is initial program.
date-written.
environment division.
data division.
working-storage section.

01  key-entered                 pic 9(3).
        88 cancel-selected      value 27.

01  player-option               pic x.
    88  record-option  value "R".
    88  playback-option  value "P".
    88  stop-option  value "S".

01  file-name                   pic x(10) value spaces.

01  saved-window                pic x(10).

procedure division.
level-1 section.
main-logic.

        display window line 10 column 20 size 40 lines 5 
                title "Test Suite Player" bottom left title "Exit(Esc)"
                        boxed pop-up saved-window.

        display "(P)layback or (R)ecord or (S)top? " line 3 column 1.
        accept player-option size 1 upper auto
                control key key-entered.
        evaluate true
             when cancel-selected
                  close window saved-window
                  continue
             when not stop-option
                  perform get-file-name
                  if not cancel-selected
                     perform run-player
                  end-if
             when stop-option
                  perform run-player
        end-evaluate.
        close window saved-window.
        exit program.

get-file-name.

        display "Enter File:  " line 5 column 1.
        accept file-name prompt control key key-entered.
           
run-player.

        evaluate true
                when record-option
                        call "w$keybuf" using 7, file-name
                when playback-option
                        call "w$keybuf" using 9, file-name
                when stop-option
                        call "w$keybuf" using 5
        end-evaluate.
Your Session will expire in 90 minutes
Notification will be shown in:
600 seconds