home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / HOOKKBS.ZIP / hook_dls.asm < prev    next >
Assembly Source File  |  1992-09-26  |  6KB  |  139 lines

  1. ;---------------------------------------------------------------------------;
  2. ; M.F.Kaplon  Begun:Tue  07-14-1992  Revised:Tue  09-15-1992
  3. ; hook_dls.asn
  4. ;
  5. ; "Copyright 1992 M.F. Kaplon"
  6. ;
  7. ; This is the dll to be used with hook_kbs.asm
  8. ;
  9. ; Its purpose is to test the system message stream for WM_CHAR and when
  10. ; selected keys are struck to post a message to hook_kbs using WM_USER+300h.
  11. ;
  12. ; The criteria for selection is : KeyStroke Down
  13. ;                                 Shift Key and either Alt or Ctrl down
  14. ;                                 valid Scan Code indicated.
  15. ;
  16. ; If those criteria are met then the msg ID is changed to WM_USER+0cfffh
  17. ; after mp1 and mp2 of the message are obtained and the mp1 and mp2
  18. ; of the message to be posted to hook_kbs are changed to contain
  19. ; mp1 = Alt/Ctrl flag = 0/1 if Alt/Ctrl down
  20. ; mp2 = Scan Code of Key on Down Stroke
  21. ;
  22. ; The function InputHook monitors the System message queue and responds
  23. ; whenever the WinGetMsg or WinPeekMsg is about to return a message.
  24. ;
  25. ; This is assembled and linked as dll by calling   dll-w386  hook_dls
  26. ;
  27. ; ths cmd file dll-w386 also moves the created dll to  c:\os2\dll
  28. ;
  29. ;---------------------------------------------------------------------------;
  30. ;
  31. ;------------------ PRELIMINARIES ----------------------
  32.  
  33. .386             ;preceeding .MODEL makes USE32 default
  34. .MODEL           FLAT,SYSCALL,OS_OS2
  35.  
  36. INCL_DOSMEMMGR      equ  1
  37. INCL_WINERRORS      equ  1
  38. INCL_WIN            equ  1
  39. INCLUDE      c:\toolkt20\asm\os2inc\os2def.inc  ;structure defns includes POINTL
  40. INCLUDE      c:\toolkt20\asm\os2inc\pmwin.inc   ;structure defns POINTL defn required
  41. INCLUDE      c:\toolkt20\asm\os2inc\bsememf.inc ;memory
  42. INCLUDE      c:\toolkt20\asm\os2inc\pmerr.inc   ;errors
  43. INCLUDELIB   c:\toolkt20\os2lib\os2386.lib      ;Library
  44.  
  45. INCLUDE      doswin32.mac                       ;macros for calls
  46.  
  47. .STACK    2048
  48.  
  49. .DATA
  50. ;------------- handles --------
  51. jr_hab            DWORD   ?    ;Anchor block handle
  52. hook              DWORD   ?    ;Handle of hook_kbs
  53. hook_mp1          DWORD   ?    ;mp1 of message
  54. hook_mp2          DWORD   ?    ;mp2 of message
  55. ;------------ structures
  56. jr_qmsg           DWORD   ?    ;Address of InputHook Message structure
  57.  
  58. ;----Shared Memory Variables---
  59. SharedMem      DWORD  0     ;base address returned
  60. SharedMemName   BYTE  "\SHAREMEM\DATAS.DAT",0
  61. SharedMemFlags DWORD  12h   ;(PAG_COMMIT OR OBJ_GETTABLE OR PAG_WRITE)
  62.  
  63. .CODE
  64.  
  65. ;----------  ESTABLISH InputHook --------------
  66. ;Has the form BOOL EXPENTRY InputHook(HAB hab, PQMSG pQmsg,ULONG fs)
  67. ;QMSG TRUCT  has  following parms as offsets
  68. ;offset 0 hwnd ,offset 4 msg ,offset 8 mp1 ,offset 12 mp2 ,etc.
  69. ;fs contains flags from WinPeekMsg function
  70. InputHook     proc
  71. ;---- GET PARAMETERS FROM STACK ---
  72.     push   ebp                  ;return address = 4 bytes,this push = 4 bytes
  73.     mov    ebp,esp              ;so first parameter is 8 bytes from top
  74.     mov    eax,[ebp+8]          ;hab
  75.     mov    jr_hab,eax           ;anchor block handle
  76.     mov    eax,[ebp+12]         ;address of qmsg truct
  77.     mov    jr_qmsg,eax          ;store address of QMSG STRUCT structure
  78. ;---- restore stack pointer
  79.     mov    esp,ebp              ;restore  stack pointer
  80.     pop    ebp                  ;back to  way it was at entrance
  81.  
  82. ;---- GET ADDRESS OF SHARED MEMORY ---
  83.     .IF SharedMem == 0
  84.        $Call DosGetNamedSharedMem,offset SharedMem,offset SharedMemName,1
  85.        .IF eax != 0
  86.           $Alarm    ;$WinErrMsg " : DosAllocSharedMem"
  87.        .ENDIF
  88.        ;---- Get handle of hook_kb and Release Shared Memory ----
  89.        mov   edi,SharedMem
  90.        mov   eax,[edi]
  91.        mov   hook,eax              ;now has handle of hook-kb
  92.        $Call DosFreeMem,SharedMem  ;release since no longer needed
  93.        .IF eax != 0
  94.           $Alarm    ;$WinErrMsg " : DosAllocSharedMem"
  95.        .ENDIF
  96.     .ENDIF
  97. ;---- IF WM_CHAR MESSAGE DETECTED -----
  98.     ;save mp1 and mp2 of message
  99.     mov  esi,jr_qmsg              ;point to message
  100.     .IF dword ptr [esi+4] == WM_CHAR
  101.          mov  eax,[esi+8]
  102.          mov  hook_mp1,eax
  103.          mov  eax,[esi+12]
  104.          mov  hook_mp2,eax
  105.      ;Test for Shift Key,Alt/Ctrl Down and Valid Scan Key
  106.      ;------ NOW [esi+8]=mp1  [esi+12]=mp2 ------
  107.          mov    ebx,hook_mp1
  108.          mov    ecx,KC_KEYUP
  109.          test   bx,cx
  110.          jnz    wm0             ;accept only on down stroke
  111. ;         jz    wm0             ;accept only on up strike
  112.          test   ebx,KC_SCANCODE ;test scan code
  113.          jz     wm0             ;jump if no valid scan code
  114.          test   ebx,KC_SHIFT
  115.          jz     wm0             ;shift key not down - dont process
  116.          mov    ecx,KC_ALT      ;? Alt Key down when msg generated
  117.          test   bx,cx           ;test scan code
  118.          jz     wm1             ;jump if Alt Key Not Hit & test Ctrl key
  119.          mov    hook_mp1,0      ;Alt/Ctrl flag
  120.          jmp    wm2
  121. wm1:     mov    ecx,KC_CTRL     ;? Ctrl-Key down
  122.          test   bx,cx
  123.          jz     wm0             ;Was neither
  124.          mov    hook_mp1,1      ;Alt/Ctrl flag
  125.          ;if ScanCode & Shift & one of Alt or Ctrl down send original message nowhere
  126. wm2:     mov    dword ptr [esi+4],WM_USER+0cfffh
  127.          xor    edx,edx
  128.          shld   edx,ebx,8       ;get high 8 bits of mp1 into dl
  129.          mov    hook_mp2,edx    ;scan code
  130.          ;WinPostMessage to HOOK_KBS
  131.          $Call WinPostMsg,hook,WM_USER+300h,hook_mp1,hook_mp2
  132.     .ENDIF
  133. wm0:mov    eax,FALSE            ;pass to next hook in chain
  134.     ret
  135. InputHook  endp
  136.  
  137. END
  138.  
  139.