home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / MKHKB2.ZIP / HOOK_KBS.DOC < prev    next >
Text File  |  1992-10-28  |  26KB  |  539 lines

  1. Document File for hook_kbs 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 : Wed  10-28-1992
  9.  
  10. Subject : Hooking the Keyboard in OS/2 2.0 and Assigning HotKeys
  11.  
  12. INTRODUCTION
  13.  
  14.   HOOK_KBS is an OS/2 equivalent of a DOS TRS program. HotKeys are defined in
  15.   a user created data file (HOOK_KBS.DAT) that assigns to a HotKey a command
  16.   to execute; the data file is read by the program when loaded. Once loaded it
  17.   intercepts the message stream and inspects all WM_CHAR messages, the
  18.   equivalent in DOS of hooking the Keyboard Interrupt. When a key stroke
  19.   meeting a HotKey definition is detected, it takes appropriate action (user
  20.   defined) otherwise it passes things along. The action taken is that of
  21.   executing the assigned command which may be a COM, EXE, CMD, or BAT file or
  22.   loading an instance of the command processor for either OS/2 or DOS. Thus
  23.   you may activate a program or load an instance of the command processor at
  24.   the flick of a HotKey without having to access an ICON. The user defineable
  25.   hot-keys are Shift-Alt-X and Shift-Ctrl-X where X is 0,1,..,9,A,B,...,Y,Z
  26.   (independent of case) for a total of 72 User-Definable Hot-Keys.
  27.  
  28.   There are THREE HARD CODED KEY COMBINATIONS (also freeing you from an ICON):
  29.  
  30.   Shift-Alt-Del(white) : unloads the program (like unloading a TSR in DOS)
  31.   Shift-Alt-Ins(white) : pops up a small OS/2 window in center of screen
  32.   Shift-Alt-End(white) : performs an orderly shut down of the system
  33.                          (same as from the DeskTop ShutDown Option)
  34.  
  35.   All hot-keys may be called from anywhere, except for Full Screen OS/2 or DOS
  36.   sessions.
  37.  
  38.   IF you edit the file HOOK_KBS.DAT, you must unload HOOK_KBS and then restart
  39.   it in order to make the new definitions ACTIVE.
  40.  
  41.  
  42.   INSTALLATION
  43.  
  44.   1: Copy the file HOOK_KBS.EXE to a directory that is defined in your path
  45.      command.
  46.  
  47.   2: Copy the file HOOK_DLS.DLL to the directory C:\OS2\DLL
  48.  
  49.   3: a. Copy the file HOOK_KBS.DAT to the directory C:\OS2
  50.      b. Edit the file HOOK_KBS.DAT to fit your requirements.
  51.  
  52.         Instructions for format are included in the comments in this file.
  53.         This one as defined, uses the 4OS2 command processor. To use the
  54.         OS/2 command processor instead replace
  55.  
  56.          C:\4OS2\4OS2.EXE  WITH  C:\OS2\CMD.EXE
  57.  
  58.   4: To Start the program, from any OS/2 command window:
  59.        If you use the OS/2 command processor
  60.  
  61.        START HOOK_KBS
  62.  
  63.          OR   If you use the 4OS2 command processor
  64.  
  65.        START HOOK_KBS C:\4OS2\4OS2.EXE
  66.  
  67.          OR   If you use yet a different command processor use its file
  68.               specification as the parameter on the command line instead
  69.               of C:\4OS2\4OS2.EXE.
  70.  
  71.    5:  OPTIONALLY you may place the starting command in a STARTUP.CMD file to
  72.        have the HOOK loaded automatically.
  73.  
  74.  
  75.   HOW THE PROGRAM WORKS
  76.  
  77.   HOOK_KBS works in conjunction with HOOK_DLS, a dynamic link module. HOOK_KBS
  78.   loads HOOK_DLS which captures Key Strokes (via sampling the system nessage
  79.   queue) from all Windows BUT Full Screen OS/2 or DOS. The KeyStrokes
  80.   assignments are USER DEFINED in a data file named HOOK_KBS.DAT and the
  81.   program recognizes keystrokes assigned to Shift-Alt-X  and Shift-Ctrl-X
  82.   where X is 0.....9 and A...Z independent of case (The restriction on X is
  83.   mine and is changeable of course).
  84.  
  85.   There are THREE HARD CODED KEY COMBINATIONS:
  86.   Shift-Alt-Del(white) : unloads the program (like unloading a TSR in DOS)
  87.   Shift-Alt-Ins(white) : pops up small OS/2 window in center of screen
  88.   Shift-Alt-End(white) : performs an orderly shut down of the system
  89.                          (same as from the DeskTop ShutDown Option)
  90.  
  91.   All hot-keys may be called from anywhere, except for the Full Screen
  92.   sessions as noted above.
  93.  
  94.   N.B.
  95.   The window opened by Shift-Alt-Ins is by default the OS/2 2.0 command
  96.   processor, CMD.EXE. To have Shift-Alt-Ins open the window with a different
  97.   command processor, e.g. that of 4OS2 (which I use) the file spec of the
  98.   command processor must be passed on the command line when hook_kbs is
  99.   invoked(e.g.) : START HOOK_KBS C:\4OS2\4OS2.EXE
  100.  
  101.   To capture from Full Screen OS/2 or DOS would require an additional program
  102.   but since my principal purpose was to create a program that would allow me
  103.   to capture keystrokes independent of where I was working and since not using
  104.   Full Screen has advantages in flexibility, I decided to go without it. For
  105.   DOS windows you may in fact readily switch back and forth from Full Screen
  106.   to Windowed via the Alt-Home combination so nothing is really lost there.
  107.  
  108.   The reason for requiring the triplet combination of Shift-Alt-X or
  109.   Shift-Ctrl-X is that besides the large number of pre-assigned keys in OS/2,
  110.   many programs use keystroke combinations for accessing specific features and
  111.   if the Hot Key is to be useful, it should not conflict. I can only remember
  112.   one program that I have seen over the years which used a Shift-Alt-X or
  113.   Shift-Ctrl-X combination and so it seems to be a fairly safe one, and one
  114.   that should not lead to conflicts. In filtering KeyStrokes the program
  115.   rejects all but the combinations Shift-Alt-X and Shift-Ctrl-X so that the
  116.   usual run of keystroke assignments of Alt-X or Ctrl-X and all Function key
  117.   combinations will be unaffected. Keystrokes are recognized on the down
  118.   stroke. I would note that the Shift-Alt or Shift-Ctrl combination is
  119.   particularly easy to access on those keyboards where the Shift Key sits
  120.   vertically between the Ctrl and Alt keys.
  121.  
  122.   As presently configured, once a key stroke combination has activated a
  123.   program, using that combination a second time will not open an additional
  124.   instance of the program but will switch back to the original. HOWEVER, IF
  125.   the opened window was used to load another program (such as a command
  126.   processor window might), then that window loses its unique identity and
  127.   using the same HotKey will activate another copy. The reason for this is
  128.   that the Identity of each window is determined by its Window title which is
  129.   defined as "Alt-X" or "Ctl-X" where X is the key used. The window popped up
  130.   with Shift-Alt-Ins has the letter ID "Ω". If another program is started from
  131.   an open window, its program title is noted as "prgname.ext Alt-X" or
  132.   "prgname.ext Ctl-X", where ext is the program's extension, and is thus not
  133.   recognized as an already existing window title.
  134.  
  135.   The program is written in 32 bit Assembler.
  136.  
  137. OVERVIEW
  138.  
  139.   FILES REQUIRED TO CREATE HOOK_KBS.EXE AND HOOK_DLS.DLL
  140.  
  141.   DOSWIN32.MAC  Macros and Equates used by Programs
  142.  
  143.   HOOK_KBS.ASM  Source for Executable, Assembled and Linked by MLC-W386.CMD
  144.  
  145.   HOOK_DLS.DEF  Define file needed by IMPLIB and linker for HOOK_DLS.ASM
  146.  
  147.   HOOK_DLS.ASM  Source for HOOK_DLS.DLL, Assembled and linked by DLL-W386.CMD
  148.  
  149.   DLL-W386.CMD  IMPLIB and HOOK_DLS.DEF create C:\TOOLKT20\OS2LIB\HOOK_DLS.LIB
  150.                 MASM then assembles HOOK_DLS.ASM, LINK386 produces HOOK_DLS.DLL
  151.                 and HOOK_DLS.DLL is copied to C:\OS2\DLL directory.
  152.  
  153.   MLC-W386.CMD  MASM assembles HOOK_KBS.ASM and LINK386 produces HOOK_KBS.EXE
  154.  
  155.  
  156.   To ASSEMBLE and LINK use the directory holding the above files as the
  157.   default and the two commands below to produce the necessary files.
  158.  
  159.   DLL-W386  HOOK_DLS
  160.   MLC-W386  HOOK_KBS
  161.  
  162.   FILES REQUIRED TO EXECUTE HOOK_KBS.EXE
  163.  
  164.   HOOK_KBS.DAT  Text File assigning programs to key strokes-read by HOOK_KBS.
  165.                 The user creates this file according to the structure outlined
  166.                 in the sample. MUST BE LOCATED IN C:\OS2. Edit the sample to
  167.                 fit your needs. Note that my assignment to C0 (Shift-Ctrl-0)
  168.                 displays a file which I have configured to list the Hot Key
  169.                 assignments. It serves as a useful reminder and I would
  170.                 recommend each user to make such an assignment. The one I
  171.                 use is a reasonable template and is included as HOT-KEY.MNU.
  172.                 All assignments fit on one screen in the default window size.
  173.  
  174.   HOOK_KBS.EXE  Exec file created above
  175.  
  176.   HOOK_DLS.DLL  Dynamic Load File Created Above - must be in C:\OS2\DLL
  177.  
  178.   DO NOT RENAME HOOK_DLS.* or HOOK_KBS.DAT as those names are coded into
  179.                 HOOK_KBS.ASM .
  180.  
  181.   The assembler used is MASM 6.0 including its built in MACROS for control
  182.   structures and segment definitions.
  183.  
  184.   The 32 bit linker (LINK386) and the 32 bit library, along with the necessary
  185.   INC files require the user to have the OS/2 TOOLKIT as well as MASM 6.0 to
  186.   assemble the program.
  187.  
  188.   PROGRAM METHOD
  189.  
  190.   The system message queue is hooked using the HK_INPUT parameter. The
  191.   function which samples the message queue is in HOOK_DLS.DLL. In the section
  192.   "Input Hook", p. 30-2 in the Programming Guide, Vol. II, it states : "The
  193.   system calls an input_hook function whenever the WinGetMsg or WinPeekMsg
  194.   functions is about to return a message."
  195.  
  196.   The installed procedure, InputHook, in HOOK_DLS.DLL tests for WM_CHAR and
  197.   when detected it further tests to see if the key combination Shift-Alt-X or
  198.   Shift-Ctrl-X was struck, with X (as defined above) on the down stroke. If
  199.   that criteria is met its POSTS to HOOK_KBS, via the API function WinPostMsg,
  200.   the message WM_USER+300h. The mp1 parameter of that message holds a flag
  201.   indicating whether Alt or Ctl was down and the mp2 parameter has the scan
  202.   code for the key X that was struck.
  203.  
  204.   HOOK_KBS determines if the Key actually struck was assigned in the file
  205.   HOOK_KBS.DAT and if so reads its parameters into the appropriate data
  206.   structure required to execute the program.
  207.  
  208.   The main program, HOOK_KBS.EXE, a PM program, sets up the hook, receives the
  209.   message indicated above and takes the appropriate action depending on the
  210.   Key Stroke. The program is established as Invisible and Not listed in the
  211.   Window List. The program should be launched from an OS/2 window with the
  212.   START command, i.e. "START HOOK_KBS" or "START HOOK_KBS C:\4OS2\4OS2.EXE"
  213.   where the latter option uses the command processor 4os2.exe as the one to be
  214.   loaded with the Shift-Alt-Ins key strokes. (Any other valid ODS/2 2.0
  215.   command processor may loaded here in place of the default c:\os2\cmd.exe).
  216.   That command can be placed in a STARTUP.CMD file for automatic loading. If
  217.   you modify the file HOOK_KBS.DAT, you must unload HOOK_KBS by
  218.   Shift-Alt-Del(white key) and then reload it to activate the new set of key
  219.   assignments.
  220.  
  221.   The key stroke combination Shift-Alt-End(white) closes down the system in
  222.   the same manner as choosing the ShutDown option from the DeskTop menu does.
  223.   Again you are relieved of hunting for space to access the desktop.
  224.  
  225.   The program automatically sets DPMI_DOS_API=ENABLED for programs whose
  226.   session type (DOS full or windowed) is defined as 4 or 7 in hook_kbs.dat.
  227.   This enables the Dos Protected Mode Interface for the DOS session. If the
  228.   Session type value of 0 is used, DPMI is not enabled as above. It is
  229.   interesting to note that setting that parameter is done by passing the
  230.   DosStartSession data structure an address holding the text string above,
  231.   even though the manual states that the field for a DOS session is reserved
  232.   and must be ZERO. Unfortunately, there are quite a few errors in the OS/2
  233.   Technical Library, but fortunately a lot of people (principally on
  234.   CompuServe) to inform you about them.
  235.  
  236.   The flow of HOOK_KBS is delineated below. The same headings are listed in
  237.   the source code in HOOK_KBS.ASM.
  238.  
  239.  
  240.   PROGRAM FLOW : HOOK_KBS
  241.  
  242.   PRELIMINARIES
  243.     Define Model and Calling Protocol
  244.     Equates for Using Macros in .DATA section
  245.     Equates for INC files
  246.     Include file listings
  247.     Prototype definitions for MASM
  248.     Structure definition for storing info on Program Assignment to Keys
  249.  
  250.   .STACK   defines an 8KB stack
  251.  
  252.   .DATA    contains variables,parameters and strings required for .CODE section
  253.  
  254.   .CODE    outlined below
  255.  
  256.   GET COMMANDLINE PARMS
  257.     See if a file spec for alternative command processor is passed on command
  258.     line and if so read it into appropriate variable.
  259.  
  260.   ESTABLISH WINDOW
  261.     WinInitialize             ;Initialize
  262.     WinCreateMessageQueue     ;Create a Message Queue
  263.     WinRegisterClass          ;Registers and identifies MainWinProc as name
  264.                               ;of Procedure for messages
  265.     WinCreateStdWindow        ;Creates window - here it is made Invisible,etc.
  266.  
  267.   IS HOOK_DLS.DLL LOADED ?    ;If yes, display message and exit
  268.  
  269.   ALLOCATE SHARED MEM AND STORE Handle Returned by WinCreateStdWindow
  270.     This is required in order to pass the Handle to HOOK_DLS
  271.  
  272.   IS DATA FILE AVAILABLE AND VALID ?
  273.     Load C:\OS2\HOOK_KBS.DAT  ;If it does not exist, exit with Error Message
  274.     Get HOOK_KBS.DAT FileSize ;Required by program for subsequent use
  275.     AllocateMemoryBuffer      ;Buffer for User Key assignments from DataFile
  276.     Copy HOOK_KBS.DAT->Buffer ;Read File into Buffer
  277.     Close HOOK_KBS.DAT        ;No longer needed
  278.     Process Data in Buffer    ;If Format Not Correct, EXIT with  Message
  279.  
  280.   ALLOCATE MEMORY FOR SWITCH LIST STRUCTURE
  281.     Do once since size needed can change as programs loaded/unloaded.
  282.  
  283.   ESTABLISH THE HOOK
  284.     DosLoadModule             ;Loads HOOK_DLS.DLL
  285.     DosQueryProcAddr          ;Get the address of the function in the DLL
  286.     WinSetHook                ;Uses the Address above and HK_INPUT to set HOOK
  287.  
  288.   CREATE MAIN MESSAGE LOOP    ;Standard PM requirement but EXIT TEST is
  289.                               ;commented out - a WM_QUIT message has no
  290.                               ;impact here
  291.  
  292.   EXIT ROUTINE                ;Note this is commented out but is included
  293.                               ;to demonstrate the overall structure of
  294.                               ;setting up a PM program
  295.  
  296.   PROCESS MESSAGE QUEUE       ;The heart of a PM program
  297.  
  298.     MainWinProc               ;Processes message queue
  299.       GET PASSED PARAMETERS FROM STACK
  300.  
  301.       RESTORE STACK POINTER AND STACK STATUS
  302.  
  303.       TEST SYSTEM QUEUE FOR MESSAGES FROM
  304.  
  305.         WM_CREATE
  306.  
  307.         WM_PAINT
  308.  
  309.         WM_CHAR
  310.  
  311.         WM_USER+300h          ;dispatched from hook_dls.dll
  312.         IF msg = WM_USER+300h
  313.           GET SCAN CODE AND ALT/CTRL FLAG
  314.           IF Shift-Alt-Del struck
  315.             Release DLL,Memory, Close Queues and Windows and Exit
  316.           ENDIF
  317.           IF Shift-Alt-End struck
  318.             Do system shutdown
  319.           ENDIF
  320.           IF Shift-Alt-Ins struck
  321.             Load small window command processor
  322.           ELSE
  323.             Reset Data Structure Address
  324.           ENDIF
  325.           TEST FOR ASSIGNED KEYS in HOOK_KBS.DAT
  326.             SETUP DATA STRUCTURES FOR ACTIVATING HOT KEY
  327.             GO THRU SWITCH LIST TO SEE IF HOT KEY ACTIVE
  328.                IF ACTIVE SWITCH TO
  329.                ELSE ACTIVATE HOT KEY PROGRAM
  330.         ENDIF
  331.  
  332.   END  PROGRAM FLOW : HOOK_KBS
  333.  
  334.   The flow of HOOK_DLS is delineated below. The same headings are listed in
  335.   HOOK_KBS.DLL.
  336.  
  337.   PROGRAM FLOW : HOOK_DLS
  338.  
  339.   PRELIMINARIES
  340.     Define Model and Calling Protocol
  341.     Equates for INC files
  342.     Include file listings
  343.  
  344.   .STACK   defines a 2KB stack
  345.  
  346.   .DATA    contains variables,parameters and strings required for .CODE section
  347.  
  348.   .CODE    delineated below
  349.  
  350.   ESTABLISH InputHook
  351.  
  352.   GET PARAMETERS FROM STACK
  353.  
  354.   GET ADDRESS OF SHARED MEMORY
  355.  
  356.       Get Handle Of Hook_kbs and Release Shared Memory
  357.  
  358.   IF WM_CHAR MESSAGE DETECTED
  359.        Save mp1 and mp2 of WM_CHAR message
  360.        Test for Shift Key,Alt/Ctrl Down and Valid Scan Key
  361.        IF ScanCode & Shift & one of Alt or Ctrl down
  362.            Send original message nowhere via WM_USER+0cfffh
  363.            WinPostMessage to HOOK_KBS via WM_USER+300h ;with ALt/Ctrl Flag and
  364.        ENDIF                                           ;ScanCode as parms
  365.   ENDIF
  366.  
  367.   END PROGRAM FLOW : HOOK_DLS
  368.  
  369. DISCUSSION
  370.  
  371.  
  372.   DOSWIN32.MAC  (Macros and Equates used by Program)
  373.  
  374.   This file contains the equates, EXTRN declarations, MACROS and Procedures
  375.   used in the ASM files. The EXTRN declarations include many more than those
  376.   used in the program but represent the accrued list of those used so far in
  377.   my OS/2 assembler programming. (As I use a new one, I just add it).
  378.  
  379.   Included are two defines used in the .DATA section of hook_kbs.asm. The
  380.   single most important MACRO is $CALL. This allows one to list parameters
  381.   after the function name in the same order as they are listed in the OS/2 2.0
  382.   Technical Manuals (and as called in C) . The macro pushes them on the stack
  383.   in the correct order and resets the stack pointer after the call. It could
  384.   clearly easily be extended to accomodate a longer parameter list. Following
  385.   that are several useful macros and three others defined via equates.
  386.  
  387.   For displaying error messages and rudimentary inline debugging, there are
  388.   three macros named $DosErrMsg, $WinErrMsg and $WinDebugMessage . The first
  389.   two are meant to be called after an API function call to display the error
  390.   number for the function used. Information on the success of the call is
  391.   returned in EAX and this must be tested. Note EAX returns differently for
  392.   DOS than for WIN calls. The user passes the text string for the Function
  393.   used on the parameter line for the $XXXErrMsg. $DosErrMsg can only be used
  394.   in Text Windows while $WinErrMsg only in PM windows.
  395.  
  396.   Finally there are several macros and procedures used for Binary <-> ASCII
  397.   conversion for both Decimal and Hex, and also for displaying numerical
  398.   results in Binary form. Not all of these are used but are included as a part
  399.   of the overall package. Note that in 32 bit mode, it is most convenient to
  400.   do all these conversion as DWORDS. These are required for numerical to ASCII
  401.   conversion for the error messages.
  402.  
  403.   HOOK_DLS.DEF
  404.  
  405.   This file is required by both IMPLIB and LINK386 in the creation of
  406.   HOOK_DLS.DLL. It identifies the function(s) exported from the DLL.
  407.  
  408.   HOOK_DLS.ASM
  409.  
  410.   This file represents the dynamic link code. It contains one function, named
  411.   InputHook whose syntax is defined by OS/2 on page 30-2 of the Programming
  412.   Guide, Vol II of the OS/2 Technical Library. This DLL monitors the system
  413.   message queue and looks for the message WM_CHAR.
  414.  
  415.   Since I decided to use WinPostMsg to return information to hook_kbs, its
  416.   handle is required in this program. The simplest way seemed to be to pass it
  417.   in a shared memory region established by hook_kbs. Thus the first task done
  418.   by the function InputHook, after setting itself up, is to get the address of
  419.   the shared memory region and to obtain the handle of hook_kbs that was placed
  420.   there by hook_kbs. After that is done, the shared memory is released.
  421.  
  422.   The program then waits for a message WM_CHAR and when that is detected the
  423.   Keyboard Parameters are tested to see if they meet the HotKey criteria. If
  424.   they do not, the message is passed on. If they do, a flag denoting whether
  425.   the Alt or Ctrl key was down is equated to the mp1 parameter and the scan
  426.   code value equated to the mp2 parameter of the message WM_USER+300h which is
  427.   posted to HOOK_KBS by WinPostMsg.
  428.  
  429.   This DLL is released from memory when hook_kbs is closed.
  430.  
  431.   HOOK_KBS
  432.  
  433.   The first four WIN... function calls are a standard calling sequence in
  434.   setting up a PM program. Since a PM program cannot display text using DOS
  435.   write calls, error messages cannot be displayed with Window Message Calls
  436.   until the Window is initialized with the first call.
  437.  
  438.   After the window is established a test is done to see if HOOK_DLS is loaded.
  439.   If it is a message is given and the program terminates. A Shared Memory area
  440.   is then established. Its sole use in this program is to furnish a method of
  441.   passing HOOK_KBS's handle to HOOK_DLS. This is done following the call to
  442.   DosAllocSharedMem. Note that eax is now tested for a non-zero value
  443.   indicating an error, as contrasted to Win calls where a 0 returned in eax
  444.   indicates an error.
  445.  
  446.   Next the program attempts to load the data file C:\OS2\HOOK_KBS.DAT. If it
  447.   does not exist, an error message is displayed and the program terminates. If
  448.   it loads, its size is obtained (note the calls are rather similar to what
  449.   you would do in DOS) and that value is used to create a buffer to hold the
  450.   file in memory. The file is read into the buffer and then closed. The big
  451.   .WHILE loop reads the buffer and assigns the Addresses of the Executable
  452.   program name and Command Line parameters and the Session type to the
  453.   appropriate member of the Structure ExecOnKb and places a 0 at the end of
  454.   strings in order that they meet the requirement of being ASCIIZ strings. If
  455.   the count of characters read in the buffer does not equal the file size or
  456.   if the data file was not properly formatted, an error message is displayed
  457.   and the program terminated; the error message displays the number of bytes
  458.   of the buffer processed when the program terminated.
  459.  
  460.   If everything is in order, a large memory block is defined to hold the data
  461.   structure of the Switch List (which is used to determine if a program is
  462.   loaded or not) and then the HOOK is established with the next three calls to
  463.   DosLoadModule, DosQueryProcAddr and WinSetHook.
  464.  
  465.   The Main Message Loop is next established. Normally this loop is exited when
  466.   WM_QUIT is received and the exit code is executed to gracefully terminate
  467.   the program. However, in this program, to ensure that it is terminated only
  468.   by the Key Combination Alt-Del, the Main Message Loop is not exitable (I
  469.   have commented out the normal tests) and I have included the Exit code only
  470.   for purposes of demonstration of what a more normal program would look like.
  471.  
  472.   The procedure MainWinProc examines the message queue. It first sets up to
  473.   get the parameters passed on the stack and goes through a series of tests
  474.   for specific messages. In a C program this would usually be a Case
  475.   statement. There is no requirement for these tests to do anything in this
  476.   case since the window is invisible but they are required to respond to
  477.   certain system calls.
  478.  
  479.   The heart of the program is the test for WM_USER+300h . WM_USER defines a
  480.   lower limit for message IDs that is (presumably) guaranteed not to conflict
  481.   with any system messages. I have arbitrarily used WM_USER + 300h. HOOK_DLS
  482.   uses this message ID in posting its information to this programs message
  483.   queue. First a test is done to see whether Alt-Del was struck and if so, the
  484.   system is closed and exited. Next a test is done to see if Alt-End was
  485.   struck in which case the routine closing down the system is called. A test
  486.   is then done to see if Alt-Ins was struck in which case the parameters for a
  487.   small command window are loaded into the apprpriate data structure. If none
  488.   of the previous are activated, tests are done to see whether the Scan Code
  489.   of the key struck is in the list read from HOOK_KBS.DAT.
  490.  
  491.   Depending on the key combination struck, the address of the program, address
  492.   of the command line parameters, the Session Type for the Key Combination
  493.   identified in the message and the Program Title ( based on the Key
  494.   combination ) are obtained and inserted into the StartData structure
  495.   required for the DosStartSession function. The Switch (Task) list is then
  496.   examined to see if the HotKey program is already loaded and its identity
  497.   unchanged. If it is, it is switched to, else DosStartSession is then called
  498.   with appropriate parameters.
  499.  
  500.   Note that WinSetFocus is called before DosStartSession. The programs started
  501.   by DosStartSession will not be in the foreground unless the program calling
  502.   DosStartSession is in the foreground and it seems reasonable that programs
  503.   called with a "HotKey" want to be in the foreground.
  504.  
  505.   The seven procedures at the very end are just routines used by parts of the
  506.   code in the program.
  507.  
  508.   I have found this program very useful, particularly with respect to programs
  509.   using COM ports. Since OS/2 will not allow you to have two programs open at
  510.   the same time that use the same COM port, this affords a rapid means of
  511.   serially accessing programs sharing a common COM port. Another use I have
  512.   found effective is to assign MENUS to some of the Hot Keys. In my sample
  513.   HOOK_KBS.DAT file, the assignment Aq (Alt-q) to loadq.cmd, is a CMD file
  514.   that displays a menu for editing a variety of different files and the
  515.   assignment Ar (Alt-r) to viewref.cmd displays a menu whose choices allow you
  516.   to View the various OnLine References of OS/2 and Toolkit20. You can readily
  517.   assign any program assigned to an ICON to a hot key, presuming the program
  518.   has an executable form or can be called as a parameter to another program.
  519.   The program represented by the HELP Icon is not amenable to this
  520.   unfortunately. But by far I have found it an efficient expediter for rapidly
  521.   accessing programs without changing anything on your DeskTop.
  522.  
  523.   As it was with TSR's in DOS, you must be careful of your assignments so that
  524.   required keys in programs are not made unavailable. That stricture was
  525.   reflected in my choice of keys to assign and reflects my particular
  526.   concerns. A natural question to ask is - are there any problems with other
  527.   programs that may be sampling the system message queue ?
  528.  
  529.   Included in OS/2 and the Toolkit are the following programs that I am aware
  530.   of which are "resident" in the above sense:
  531.  
  532.     PULSE    From Productivity Group - Samples Processor Activity
  533.     KWIKINF  From OS/2 ToolKit20     - An OnLineReference Access
  534.     PMSPY    From OS/2 ToolKit20     - A Message queue trace
  535.  
  536.   I have not detected any problems with HOOK_KBS loaded with any or all of the
  537.   above programs active, independent of the order of loading.
  538.  
  539.