home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / tools / hookbsm / hookkbsm.doc < prev    next >
Encoding:
Text File  |  1993-04-30  |  17.2 KB  |  342 lines

  1. Document File for HOOKKBSM PROGRAM
  2.  
  3. From : Morton F. Kaplon  CIS : 73457,437
  4.        1047 Johnston Drive
  5.        Bethlehem PA 18017
  6.        (215)758-9686
  7.  
  8. Revised and Updated : Fri  04-30-1993
  9.  
  10. Subject : Hooking the Keyboard in OS/2 2.0, Assigning HotKeys,
  11.           MACROS:Recording and Playing Back KeyStrokes and Mouse Actions
  12.  
  13. INTRODUCTION and OVERVIEW
  14.  
  15.   HOOKKBSM is an OS/2 equivalent of a DOS TRS program. Operationally it
  16.   consists of two cooperating entities. One is the DLL(dynamic link library)
  17.   named HOOKDLSM.DLL and the other the executable HOOKKBSM.EXE. When HOOKKBSM
  18.   is loaded, it in turns loads HOOKDLSM into memory where it remains until it
  19.   is removed from memory by an explicit call (made by HOOKKBSM when it is
  20.   closed). Since HOOKDLSM is a dynamic link library, it can in principle
  21.   interact with programs other than the one which loaded it. In this
  22.   application, the DLL contains two functions. One named INITIALIZE which is a
  23.   specific link between it and HOOKKBSM, and the other named InputHook which
  24.   is called by the system whenver the WinGetMsg or the WinPeekMsg functions
  25.   are about to return a message. Thus the DLL has access to all messages in
  26.   the system message queue.
  27.  
  28.   When HOOKKBSM is loaded, it displays a small window named "Hook" in the
  29.   lower right Corner of the Desktop. In addition to providing evidence of the
  30.   Active existence of HOOKKBSM, the window is used to display messages when
  31.   operating in MacroRecord or MacroPlayBack mode and when the file containing
  32.   user assignment data has been changed and re-read into memory.
  33.  
  34.   In its role as a hot-key actuator it tests ALL WM_CHAR messages in the
  35.   message queue, the equivalent in DOS of hooking the Keyboard Interrupt. When
  36.   a key stroke meeting a HotKey definition is detected (one of the sequence
  37.   Shift-Alt/Ctrl-X), HOOKDLSM notifies HOOKKBSM by POSTing a message to it
  38.   with the mp1 parameter holding a flag indicating whether the Alt or Ctrl key
  39.   was struck along with the Shift Key and the parameter mp2 holding the Scan
  40.   Code of the Key X that was struck. HOOKKBSM takes action if the key X is
  41.   defined in its Data structures.
  42.  
  43.   Its role as a Macro Recorder is initiated by the user action of
  44.   pressing the Shift-Ctrl-LeftArrow combination. HOOKKBSM is notified of
  45.   this by the action above, and in turn Calls HOOKDLSM setting a flag to
  46.   ON that enables the recording of all messages from the system message
  47.   queue but WM_TIMER (its behavior seems unaffected if WM_TIMER is not
  48.   excluded). The messages are saved in a DataBuffer. Macro recording is
  49.   turned OFF by pressing the combination Shift-Ctrl-RightArrow, which
  50.   results in HOOKKBSM Calling the DLL and setting the flag to OFF. The
  51.   set of messages in the Data Buffer is played back by pressing the
  52.   Shift-Ctrl-Ins key. If the combination Shft-Ctl-PgDn is struck before
  53.   a new macro recording is started, the content of the buffer is saved,
  54.   in ASCII text form to a file named HOOKKBSM.MAC. The file is a set of
  55.   records, one for each message, in the format indicated below. This is
  56.   sort of like a "spy" program and allows one to see what goes on behind
  57.   the scenes, so to speak.
  58.  
  59. WinHandle MessageID msgParam1 msgParam2  msgTime  X_ScreenP Y_ScreenP TaskListName
  60.  
  61.   The set of Hot-Keys for which the User may define actions is that for which
  62.   X = 0,1,..,9,A,B,...,Y,Z (independent of case), a total of 72. Values of X =
  63.   1..9 on the White Keys on the KeyPad are reserved for a variety of program
  64.   defined uses as well as the key on the regular keyboard, having the symbol
  65.   "?" in the UpperCase position.
  66.  
  67.   The reason for requiring the triplet combination of Shift-Alt-X or
  68.   Shift-Ctrl-X is that besides the large number of pre-assigned keys in OS/2,
  69.   many programs use keystroke combinations for accessing specific features and
  70.   if the Hot Key is to be useful, it should not conflict. I can only remember
  71.   one program that I have seen over the years which used a Shift-Alt-X or
  72.   Shift-Ctrl-X combination and so it seems to be a fairly safe one, and one
  73.   that should not lead to conflicts. In filtering KeyStrokes the program
  74.   rejects all but the combinations Shift-Alt-X and Shift-Ctrl-X so that the
  75.   usual run of keystroke assignments of Alt-X or Ctrl-X and all Function key
  76.   combinations will be unaffected. Keystrokes are recognized on the down
  77.   stroke. I would note that the Shift-Alt or Shift-Ctrl combination is
  78.   particularly easy to access on those keyboards where the Shift Key sits
  79.   vertically between the Ctrl and Alt keys.
  80.  
  81.   For the User defined HotKeys, HOOKKBSM reads the User created file
  82.   HOOKKBSM.DAT which defines the actions associated with each Hot-Key. The
  83.   action taken is that of executing an assigned command which may be a COM,
  84.   EXE, CMD, or BAT file or loading an instance of the command processor for
  85.   either OS/2 or DOS. Thus you may activate a program or load an instance of
  86.   the command processor at the flick of a HotKey without having to access an
  87.   ICON. Included in the files is a sample HOOKKBSM.DAT(one that I use) which
  88.   defines the format to be followed and which the user should modify to
  89.   reflect his/her requirements.
  90.  
  91.   IF you edit the file HOOKKBSM.DAT when HOOKKBSM is active, you need only
  92.   use the key combination Shift-Alt-UpArrow(White) to activate the changes.
  93.   The "Hook" window in the lower right screen flashes "USER Updated" when this
  94.   is done. This update fixes an assumption about editors made previously.
  95.   Namely that files were not terminated with a Ctrl-Z. That was causing
  96.   errors when many editors (those coming with OS/2) were used that place
  97.   a Ctrl-Z at the EOF.
  98.  
  99.   In addition there are several features also assigned to Hot Keys which are
  100.   of a diagnostic or informational nature and may be of some educational use
  101.   in understanding some aspects of OS/2. Finally there are some housekeeping
  102.   aspects (removing the "TSR", and closing down the system) and one OS/2 PopUp
  103.   Command window included in the pre-assigned category.
  104.  
  105.   <--------------------- Pre-Assigned KEY ASSIGNMENTS ----------------------->
  106.   Shft-Alt-Del(wkp)      : unloads program (like unloading a TSR in DOS)
  107.   Shft-Alt-End(wkp)      : performs an orderly shut down of the system
  108.                            (same as from the DeskTop ShutDown Option)
  109.   Shft-Alt-UpArrow(wkp)  : Update DataStructures if HOOKKBSM.DAT changed
  110.   Shft-Alt-Ins(wkp)      : pops up a small OS/2 window in center of screen
  111.   Shft-Ctl-LftArrow(wkp) : Start Macro Recording
  112.   Shft-Ctl-RgtArrow(wkp) : Stop Macro Recording
  113.   Shft-Ctl-PgDn(wkp)     ; Write Last Macro as ASCII text to file HOOKKBSM.MAC
  114.   Shft-Ctl-Ins(wkp)      : Playback Macro Using Current Window SetUp
  115.   Shft-Ctl-?(tkb)        : Display Listing of User Defined HotKeys
  116.   Shft-Alt-?(tkb)        : Display Listing of Pre-assigned Hot Keys
  117.  
  118.   Shft-Alt-5(wkp)        : For window under Mouse,Displays Handle,WindowClass
  119.                          : Window Type(10h/20h bit),Parent and Owner
  120.   Shft-Ctl-5(wkp)        : WindowEnumerator from Window Under Mouse
  121.  
  122.   wkp = White Key Pad   tkb = typewriter key board
  123.   All hot-keys callable from anywhere, except Full Screen OS/2 or DOS sessions.
  124.  
  125.  
  126.   INSTALLATION
  127.  
  128.   1: Copy the file HOOKKBSM.EXE to a directory that is defined in your path
  129.      command.
  130.  
  131.   2: Copy the file HOOKDLSM.DLL to the directory C:\OS2\DLL
  132.  
  133.   3: a. Copy the file HOOKKBSM.DAT to the directory C:\OS2
  134.      b. Edit the file HOOKKBSM.DAT to fit your requirements.
  135.  
  136.         Instructions for format are included in the comments in this file.
  137.         This one as defined, uses the 4OS2 command processor. To use the
  138.         OS/2 command processor instead replace
  139.  
  140.          C:\4OS2\4OS2.EXE  WITH  C:\OS2\CMD.EXE
  141.  
  142.   4: a. Copy the file HOT-KEYS.PRG to C:\OS2
  143.      b. Copy the file HOT-KEYS.USR to C:\OS2
  144.      c. Edit the file HOT-KEYS.USR to reflect your assignments as made
  145.         in HOOKKBSM.DAT
  146.  
  147.   5: To Start the program, from any OS/2 command window:
  148.        If you use the OS/2 command processor
  149.  
  150.        START HOOKKBSM
  151.  
  152.          OR   If you use the 4OS2 command processor
  153.  
  154.        START HOOKKBSM C:\4OS2\4OS2.EXE
  155.  
  156.          OR   If you use yet a different command processor use its file
  157.               specification as the parameter on the command line instead
  158.               of C:\4OS2\4OS2.EXE.
  159.  
  160.   6:  OPTIONALLY you may place the starting command in a STARTUP.CMD file to
  161.        have the HOOK loaded automatically.
  162.  
  163. OVERVIEW
  164.  
  165.   FILES REQUIRED TO CREATE HOOKKBSM.EXE AND HOOKDLSM.DLL
  166.  
  167.   DOSWIN32.MAC  Macros and Equates used by Programs
  168.  
  169.   HOOKKBSM.ASM  Source for Executable, Assembled and Linked by MLC-W386.CMD
  170.  
  171.   HOOKDLSM.DEF  Define file needed by IMPLIB and linker for HOOKDLSM.ASM
  172.  
  173.   HOOKDLSM.ASM  Source for HOOKDLSM.DLL, Assembled and linked by DLL-W386.CMD
  174.  
  175.   DLL-W386.CMD  IMPLIB and HOOKDLSM.DEF create C:\TOOLKT20\OS2LIB\HOOKDLSM.LIB
  176.                 MASM then assembles HOOKDLSM.ASM, LINK386 produces HOOKDLSM.DLL
  177.                 and HOOKDLSM.DLL is copied to C:\OS2\DLL directory.
  178.  
  179.   MLC-W386.CMD  MASM assembles HOOKKBSM.ASM and LINK386 produces HOOKKBSM.EXE
  180.  
  181.   To ASSEMBLE and LINK use the directory holding the above files as the
  182.   default and the two commands below (in order given) to create the necessary
  183.   DLL and EXE files.
  184.  
  185.   DLL-W386  HOOKDLSM
  186.   MLC-W386  HOOKKBSM
  187.  
  188.   FILES REQUIRED TO EXECUTE HOOKKBSM.EXE
  189.  
  190.   HOT-KEYS.PRG  This is a text file called by the HotKey combination
  191.                 Shft-Alt-?..It displays a listing of the HARD CODED
  192.                 Key Assignments in a format contained in a Standard
  193.                 OS/2 window. It should not be edited and should be
  194.                 used as is. MUST BE LOCATED IN C:\OS2.
  195.  
  196.   HOT_KEYS.USR  This is a text file called by the HotKey combination
  197.                 Shft-Ctl-?. It must be created by the USER to reflect
  198.                 his/her key assignments as contained in HOOKKBSM.DAT.
  199.                 The file presented is a Template that contains space
  200.                 for all the User assignable HotKeys and which will
  201.                 be contained in a standard OS/2 text window.
  202.                 MUST BE LOCATED IN C:\OS2.
  203.  
  204.   HOOKKBSM.DAT  Text File assigning programs to key strokes-read by HOOKKBSM.
  205.                 The USER creates this file according to the structure outlined
  206.                 in the sample. MUST BE LOCATED IN C:\OS2. Edit the sample to
  207.                 fit your needs.
  208.  
  209.   HOOKDLSM.DLL  Dynamic Load File Created Above - must be in C:\OS2\DLL
  210.  
  211.   HOOKKBSM.EXE  Exec file created above
  212.  
  213.   DO NOT RENAME HOOKDLSM.* or HOOKKBSM.DAT as those names are coded into
  214.                 HOOKKBSM.ASM .
  215.  
  216.   The program is written in 32 bit Assembler. The assembler used is MASM 6.00B
  217.   including its built in MACROS for control structures and segment
  218.   definitions.
  219.  
  220.   The 32 bit linker (LINK386) and the 32 bit library, along with the necessary
  221.   INC files require the user to have the OS/2 TOOLKIT as well as MASM 6.00B to
  222.   assemble the program.
  223.  
  224.   PROGRAM METHOD
  225.  
  226.   The system message queue is hooked using the HK_INPUT parameter. The
  227.   function which samples the message queue is in HOOKDLSM.DLL. In the section
  228.   "Input Hook", p. 30-2 in the Programming Guide, Vol. II, it states : "The
  229.   system calls an input_hook function whenever the WinGetMsg or WinPeekMsg
  230.   functions is about to return a message."
  231.  
  232.   There are two procedures in HOOKDLSM.DLL. One is named Initialize and is
  233.   used to pass parameters between HOOKKBSM and HOOKDLSM. The other named
  234.   InputHook tests for WM_CHAR and when detected it further tests to see if the
  235.   key combination Shift-Alt-X or Shift-Ctrl-X was struck, with X (as defined
  236.   above) on the down stroke. If that criteria is met its POSTS to HOOKKBSM,
  237.   via the API function WinPostMsg, the message WM_USER+300h. The mp1 parameter
  238.   of that message holds a flag indicating whether Alt or Ctl was down and the
  239.   mp2 parameter has the scan code for the key X that was struck.
  240.  
  241.   IF at any time the user starts to record a Macro by hitting the
  242.   HotKeyCombination Shft-Ctrl-LeftArrow, then the program HOOKKBSM calls
  243.   the program HOOKDLSM and sets a flag in HOOKDLSM so that the procedure
  244.   InputHook also saves ALL messages in the system queue (but WM_TIMER)
  245.   to a memory Buffer. Omitting the WM_TIMER messages (its inclusion
  246.   seems to make no difference) saves buffer space. Hitting the
  247.   combination Shft-Ctrl-RightArrow results in HOOKKBSM resetting the
  248.   flag in HOOKDLSM that so the recording of all messages is turned OFF.
  249.   If the combination Shft-Ctl-PgDn is struck before a new macro
  250.   recording is started, the content of the buffer is saved, in ASCII
  251.   text form to a file named HOOKKBSM.MAC. The file is a set of records,
  252.   one for each message, in the format indicated below.
  253.  
  254. WinHandle MessageID msgParam1 msgParam2  msgTime  X_ScreenP Y_ScreenP TaskListName
  255.  
  256.   The main program, HOOKKBSM.EXE, a PM program, sets up the hook, receives the
  257.   message indicated above and takes the appropriate action depending on the
  258.   Key Stroke. The program is established as visible and is listed in the
  259.   Window List. The small window displayed is located in the lower right hand
  260.   corner of the Desktop. The program should be launched from an OS/2 window
  261.   with the START command, i.e. "START HOOKKBSM" or "START HOOKKBSM
  262.   C:\4OS2\4OS2.EXE" where the latter option uses the command processor
  263.   4os2.exe as the one to be loaded with the Shift-Alt-Ins key strokes. (Any
  264.   other valid ODS/2 2.0 command processor may loaded here in place of the
  265.   default c:\os2\cmd.exe). That command can be placed in a STARTUP.CMD file
  266.   for automatic loading.
  267.  
  268.   HOOKKBSM determines if the Key actually struck was assigned in the file
  269.   HOOKKBSM.DAT and if so reads its parameters into the appropriate data
  270.   structure required to execute the program.
  271.  
  272.   The key stroke combination Shift-Alt-End(white) closes down the system in
  273.   the same manner as choosing the ShutDown option from the DeskTop menu does.
  274.   Again you are relieved of hunting for space to access the desktop.
  275.  
  276.   The program automatically sets DPMI_DOS_API=ENABLED for programs whose
  277.   session type (DOS full or windowed) is defined as 4 or 7 in HOOKKBSM.dat.
  278.   This enables the Dos Protected Mode Interface for the DOS session. If the
  279.   Session type value of 0 is used, DPMI is not enabled as above. It is
  280.   interesting to note that setting that parameter is done by passing the
  281.   DosStartSession data structure an address holding the text string above,
  282.   even though the manual states that the field for a DOS session is reserved
  283.   and must be ZERO. Unfortunately, there are quite a few errors in the OS/2
  284.   Technical Library, but fortunately a lot of people (principally on
  285.   CompuServe) to inform you about them.
  286.  
  287.   The program also contains a NASCENT  Macro Record and Playback facility
  288.   which is rather limited in its capabilities. AT the present time the
  289.   PlayBack is limited to just the most recent Macro recorded. When Macros are
  290.   recorded, what is saved are the parameters of the message queue as contained
  291.   in the structure QMSG
  292.      QMSG    STRUC
  293.      qmsg_hwnd       DD      ?
  294.      qmsg_msg        DD      ?
  295.      qmsg_mp1        DD      ?
  296.      qmsg_mp2        DD      ?
  297.      qmsg_time       DD      ?
  298.      qmsg_ptl        DB      SIZE POINTL DUP (?)
  299.      qmsg_reserved   DD      ?
  300.      QMSG    ENDS
  301.  
  302.      POINTL  STRUC
  303.      ptl_x   DD      ?
  304.      ptl_y   DD      ?
  305.      POINTL  ENDS
  306.  
  307.   The first six components of QMSG make up each Macro RECORD. The first
  308.   element qmsg_hwnd is the handle of the window that was created during the
  309.   actual macro recording. IF a series of windows were opened during that
  310.   recording and then closed, when the macro is played back, the actual handle
  311.   assigned when windows are opened is not necessarily the same as that
  312.   contained in the message and thus the value in the macro record is of no use
  313.   in the playback. IF the window display is different during playback than
  314.   when recorded, mouse actions will be played back differently. Thus, in
  315.   playing back any macro one must be certain that the window set up initially
  316.   is the same as when recorded.
  317.  
  318.   The playback currently does not handle any other mouse actions than its
  319.   movement and the left mouse button actions.
  320.  
  321.   It also does not playback the Alt-Esc or Alt-Tab sequences, and only
  322.   plays back those involving CTrl-Esc if the undocumented message 82h is
  323.   trapped for playback. It also does incomplete PlayBacks in those cases
  324.   where two windows on screen are highlighted at the same time, such as
  325.   a Table of Contents window included when On Line documentation as
  326.   brought up by, for example by the command VIEW REXX from the OS/2
  327.   prompt. In these cases, and this is one of the problems puzzling me,
  328.   the keystrokes selecting commands from the Table of Contents appear to
  329.   be played back before the window is completely painted on the screen.
  330.   This appears more dramatically if you use Mouse movements.
  331.  
  332.   The problem does not occur, when the screen selected, has a single
  333.   highlighted component, such as HELP.
  334.  
  335.   The macros that record removing items, such as F3 from Table of Contents
  336.   Screens and ALt-F4 to close Containers show problems. Macros recognize
  337.   F3 in closing Table of Contents and also Esc, but do not play back
  338.   the Alt-F4 or Alt-Close(via the mouse) choices.
  339.  
  340.  
  341.  
  342.