home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / hookkbsm.zip / HOOKDLSM.ASM < prev    next >
Assembly Source File  |  1993-01-01  |  8KB  |  199 lines

  1. ;---------------------------------------------------------------------------;
  2. ; M.F.Kaplon  Begun:Wed  09-30-1992    Revised:Fri  01-01-1993
  3. ; hookdlsm.asn  ; "Copyright 1992 M.F. Kaplon"
  4. ;
  5. ; This is the dll to be used with hookkbsm.asm
  6. ; Its purpose is to test the system message stream for WM_CHAR and when
  7. ; selected keys are struck to post a message to hookkbsm using WM_USER+300h.
  8. ;
  9. ; The criteria for selection are on KeyStroke Down:
  10. ; Shift Key and either Alt or Ctrl down+valid Scan Code indicated
  11. ; If those criteria are met then the msg ID is changed to WM_USER+0cfffh
  12. ; after mp1 and mp2 of the message are obtained and the mp1 and mp2
  13. ; of the message to be posted to hookkbsm are changed to contain
  14. ; mp1 = Alt/Ctrl flag = 0/1 if Alt/Ctrl down ; mp2 = Scan Code
  15. ; of Key on Down Stroke
  16. ;
  17. ; Additionally, it records all messages (with any restrictions as coded )
  18. ; when the flag (set by Shift-Ctrl-LeftArrow(White)) RecordOn = 1. The flag is
  19. ; turned off by Shift-Ctrl-RightArrow(White). The messages are stored in a
  20. ; buffer that is created in hookdlsm and whose address is passed to hookkbsm
  21. ; in the register EAX when the procedure INITIALIZE is called with EAX = 0.
  22. ;
  23. ; The function InputHook monitors the System message queue and responds
  24. ; whenever the WinGetMsg or WinPeekMsg is about to return a message.
  25. ;
  26. ; This is assembled and linked as dll by calling  dll-w386  hookdlsm
  27. ; The cmd file dll-w386 also moves the created dll to  c:\os2\dll
  28. ;
  29. ; In calling the procedure "Initialize"  in hookdlsm.dll from hookkbsm
  30. ; Values are passed in registers and the procedures are called by JUMPs
  31. ; after placing the values in the registers the return offset
  32. ; of the return location. The functions examine the registers and take
  33. ; appropriate action.
  34. ;
  35. ;---------------------------------------------------------------------------;
  36. ;
  37. ;------------------ PRELIMINARIES ----------------------
  38.  
  39. NUMBUFS            equ    1     ; Uncomment if need number routines
  40.  
  41. .386             ;preceeding .MODEL makes USE32 default
  42. .MODEL           FLAT,SYSCALL,OS_OS2
  43.  
  44. RecdLnth            equ 28
  45.  
  46. INCL_DOSMEMMGR      equ  1
  47. INCL_WINERRORS      equ  1
  48. INCL_WIN            equ  1
  49.  
  50. INCLUDE      c:\toolkt20\asm\os2inc\os2def.inc  ;structure defns includes POINTL
  51. INCLUDE      c:\toolkt20\asm\os2inc\pmwin.inc   ;structure defns POINTL defn required
  52. INCLUDE      c:\toolkt20\asm\os2inc\bsememf.inc ;memory
  53. INCLUDE      c:\toolkt20\asm\os2inc\pmerr.inc   ;errors
  54. INCLUDELIB   c:\toolkt20\os2lib\os2386.lib      ;Library
  55.  
  56. INCLUDE      doswin32.mac                       ;macros for calls
  57.  
  58. .STACK    4096
  59.  
  60. .DATA
  61.  
  62. IFDEF NUMBUFS                      ;To use  UNCOMMENT NUMBUFS equate above
  63.   $DefineNumBufs
  64. ENDIF
  65.  
  66. ;------------- handles --------
  67. hab               DWORD   ?
  68. ih_hab            DWORD   ?    ;Anchor block handle
  69. hook              DWORD   ?    ;Handle of hook_kbs from Shared Mem offset 0
  70. hook_msgID        DWORD   ?    ;message ID
  71. hook_mp1          DWORD   ?    ;mp1 of message
  72. hook_mp2          DWORD   ?    ;mp2 of message
  73.  
  74. JR_Counter        DWORD   0    ;Counter for records in JournalRecord
  75. JR_Count          DWORD   ?    ;Final Count of JournalRecord Session
  76. RecordOn          DWORD   0    ;Flag INdicating Record Off/ON = 0/1
  77. MaxCount          DWORD   1000  ;Maximum qmsg structure counts
  78. AddrCtr           DWORD   0    ;increment counter
  79. ;------------ structures
  80. ih_qmsg           DWORD   ?    ;Address of InputHook Message structure
  81. ih_opt            DWORD   ?    ;Change Option
  82.  
  83. ;----Shared Memory Variables---
  84. PlayBackQMSG    DWORD  25000 dup(0)  ;store 892 recorded messages RecdLnth bytes per message
  85.  
  86. .CODE
  87.  
  88. ;----------  ESTABLISH InputHook --------------
  89. ;Has the form BOOL EXPENTRY InputHook(HAB hab, PQMSG pQmsg,ULONG fs)
  90. ;QMSG STRUCT  has  following parms as offsets
  91. ;offset 0 hwnd ,offset 4 msg ,offset 8 mp1 ,offset 12 mp2 ,etc.
  92. ;fs contains flags from WinPeekMsg function
  93. InputHook     proc
  94. ;---- GET PARAMETERS FROM STACK ---
  95.     push   ebp                  ;return address = 4 bytes,this push = 4 bytes
  96.     mov    ebp,esp              ;so first parameter is 8() bytes from top
  97.     mov    eax,[ebp+8]          ;hab
  98.     mov    ih_hab,eax           ;anchor block handle
  99.     mov    eax,[ebp+12]         ;address of qmsg truct
  100.     mov    ih_qmsg,eax          ;store address of QMSG STRUCT structure
  101.     mov    eax,[ebp+16]         ;change option
  102.     mov    ih_opt,eax
  103. ;---- restore stack pointer
  104.     pop    ebp                  ;back to  way it was at entrance
  105.    pusha
  106. ;---- Get Message Signature
  107.     mov    esi,ih_qmsg          ;point to message
  108. ;save message parameters
  109.     mov  eax,[esi]
  110.     mov  eax,[esi+4]            ;message ID
  111.     mov  hook_msgID,eax
  112.     mov  eax,[esi+8]            ;mp1
  113.     mov  hook_mp1,eax
  114.     mov  eax,[esi+12]           ;mp2
  115.     mov  hook_mp2,eax
  116. ;---- IF Recording, send same parameters as in JournalRecordHook back to hookkbsm
  117. ;---- 4864 = 1300h = WM_USER+300h
  118. ;---- Inclusion of WM_TIMER realaly slows down playback
  119.     .IF RecordOn == 1 && hook_msgID != WM_TIMER
  120.         mov  edi,offset PlayBackQMSG
  121.         inc  JR_Counter
  122.         mov  ebx,AddrCtr
  123.         mov  eax,[esi]          ;hwnd
  124.         mov  [edi+ebx],eax
  125.         mov  eax,[esi+4]        ;message ID
  126.         mov  [edi+4+ebx],eax
  127.         mov  eax,[esi+8]        ;mp1
  128.         mov  [edi+8+ebx],eax
  129.         mov  eax,[esi+12]       ;mp2
  130.         mov  [edi+12+ebx],eax
  131.         mov  eax,[esi+16]       ;time
  132.         mov  [edi+16+ebx],eax
  133.         mov  eax,[esi+20]
  134.         mov  [edi+20+ebx],eax   ;x coordinate
  135.         mov  eax,[esi+24]
  136.         mov  [edi+24+ebx],eax   ;y coordinate
  137.         Add  AddrCtr,RecdLnth
  138.         mov  eax,JR_Counter
  139.         .IF  eax > MaxCount
  140.              mov   RecordOn,0
  141.              $WinInfMsg   "  !! Buffer Limit                Shft-Ctrl-RightArrow to EndRecord!!"
  142.         .ENDIF
  143.     .ENDIF
  144. ;---- IF ONLY WM_CHAR MESSAGE DETECTED test for keystrokes-----
  145.     .IF hook_msgID == WM_CHAR
  146.      ;------Test for Shift Key,Alt/Ctrl Down and Valid Scan Key
  147.          mov    ebx,hook_mp1
  148.          test   bx,KC_KEYUP     ;KeyDown ?
  149.          jnz    wm0             ;accept only on down stroke
  150.          test   bx,KC_SCANCODE  ;test scan code
  151.          jz     wm0             ;jump if no valid scan code
  152.          test   bx,KC_SHIFT
  153.          jz     wm0             ;shift key not down - dont process
  154.          test   bx,KC_ALT       ;? Alt Key down when msg generated
  155.          jz     wm1             ;jump if Alt Key Not Hit & test Ctrl key
  156.          mov    hook_mp1,0      ;Alt/Ctrl flag
  157.          jmp    wm2
  158. wm1:     test   bx,KC_CTRL     ;? Ctrl-Key down
  159.          jz     wm0             ;Was neither
  160.          mov    hook_mp1,1      ;Alt/Ctrl flag
  161. wm2:     xor    edx,edx
  162.          shld   edx,ebx,8       ;get high 8 bits of mp1 into dl
  163.          mov    hook_mp2,edx    ;scan code
  164.          ;----- WinPostMessage to HOOK_KBS Using SEND causes problem on Macro playbacks
  165.         $Call WinPostMsg,hook,WM_USER+300h,hook_mp1,hook_mp2
  166.          popa
  167.          mov    eax,TRUE        ;do not pass to next hook
  168.          ret
  169.     .ENDIF                      ;IF WM_CHAR
  170. wm0:popa
  171.     mov    eax,FALSE            ;pass to next hook in chain
  172.     ret
  173. InputHook  endp
  174.  
  175. Initialize  Proc                ;HwndMainFrame  in ebx
  176.     .IF   eax == 0              ;Initialization set up
  177.         mov    hook,ebx
  178.         mov    eax,offset PlayBackQMSG
  179.         ret
  180.     .ENDIF
  181.     .IF   eax == 1             ;Initialize for Recording Session
  182.         mov   RecordOn,1
  183.         mov   JR_Count,0
  184.         mov   JR_Counter,0
  185.         mov   AddrCtr,0
  186.         ret
  187.     .ENDIF
  188.     .IF   eax == 2             ;Save Count Return Total in eax
  189.         .IF   RecordOn != 0    ;stopped below maxCount
  190.             mov   RecordOn,0
  191.         .ENDIF
  192.         mov   eax,JR_Counter     ;return total count
  193.        ret
  194.     .ENDIF
  195. Initialize  Endp
  196.  
  197. End
  198.  
  199.