home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / PUTKEY.ASM < prev    next >
Assembly Source File  |  1992-10-16  |  11KB  |  238 lines

  1. ; File......: PUTKEY.ASM
  2. ; Author....: Ted Means
  3. ; Date......: $Date:   16 Oct 1992 00:00:56  $
  4. ; Revision..: $Revision:   1.4  $
  5. ; Log file..: $Logfile:   C:/nanfor/src/putkey.asv  $
  6. ; This is an original work by Ted Means and is placed in the
  7. ; public domain.
  8. ;
  9. ; Modification history:
  10. ; ---------------------
  11. ;
  12. ; $Log:   C:/nanfor/src/putkey.asv  $
  13. ;  
  14. ;     Rev 1.4   16 Oct 1992 00:00:56   GLENN
  15. ;  Just making sure we have Ted's latest revisions.
  16. ;  
  17. ;     Rev 1.3   01 Jul 1992 01:07:02   GLENN
  18. ;  PUTKEY.ASM now bypasses the BIOS completely and uses Clipper's
  19. ;  internal event handler to stuff the keystroke.  Modifications by
  20. ;  Ted Means.
  21. ;  
  22. ;     Rev 1.2   15 Aug 1991 23:07:10   GLENN
  23. ;  Forest Belt proofread/edited/cleaned up doc
  24. ;  
  25. ;     Rev 1.1   14 Jun 1991 19:54:56   GLENN
  26. ;  Minor edit to file header
  27. ;  
  28. ;     Rev 1.0   01 Apr 1991 01:03:48   GLENN
  29. ;  Nanforum Toolkit
  30. ;  
  31.  
  32. ; $DOC$
  33. ; $FUNCNAME$
  34. ;     FT_PUTKEY()
  35. ; $CATEGORY$
  36. ;     Keyboard/Mouse
  37. ; $ONELINER$
  38. ;     Stuff a keystroke into the keyboard buffer
  39. ; $SYNTAX$
  40. ;     FT_PUTKEY( <nKeyValue> ) -> lResult
  41. ; $ARGUMENTS$
  42. ;     <nKeyValue> is the INKEY() value of the keystroke to be stuffed.
  43. ; $RETURNS$
  44. ;    .T. if the keystroke was put into the keyboard buffer.
  45. ;    .F. if nKeyValue was invalid or the buffer was full.
  46. ; $DESCRIPTION$
  47. ;    This function is similar to the KEYBOARD command, with a few
  48. ;    exceptions. First, this function does not clear the keyboard buffer
  49. ;    before inserting the keystroke.  In addition, since it uses the
  50. ;    Inkey() value, you can stuff any key, including function keys, into
  51. ;    the keyboard buffer. However, this also means that unlike the KEYBOARD
  52. ;    command, you can only stuff one keystroke at a time.
  53. ;
  54. ;    You can easily create a User-Defined Command that makes this function
  55. ;    even more like the KEYBOARD command.  For example,
  56. ;
  57. ;        #command KEYSTROKE <key> => FT_PUTKEY( <key> )
  58. ;
  59. ;    will create a command called KEYSTROKE that could be used as a
  60. ;    companion command to KEYBOARD.  The only difference is that it would
  61. ;    insert a single keystroke instead of a string.
  62. ;
  63. ;    Be aware that this function makes use of Clipper's internal event
  64. ;    handler.  If you don't like using internals, then don't use this
  65. ;    function, you sniveling coward.
  66. ;
  67. ;    This function is written to adhere to Turbo Assembler's IDEAL mode.
  68. ;    To use another assembler, rearrange the SEGMENT and PROC directives
  69. ;    and make any other necessary changes to the source code.
  70. ; $EXAMPLES$
  71. ;      FT_PUTKEY( -9 )   //  Stuff the F10 key
  72. ;      FT_PUTKEY( 276 )  //  Stuff the Alt T key
  73. ;      KEYSTROKE 28      //  Stuff the F1 key using a User-Defined Command
  74. ; $END$
  75.  
  76. IDEAL
  77.  
  78. Public   FT_PutKey
  79.  
  80. Extrn    __ParInfo:Far
  81. Extrn    __Parni:Far
  82. Extrn    __RetL:Far
  83. Extrn    __evLow:Far                         ; Internal!!  Sniveling cowards
  84.                                              ; beware!
  85.  
  86. Segment  _NanFor   Word      Public    "CODE"
  87.          Assume    CS:_NanFor
  88.  
  89. Proc     FT_PutKey Far
  90.  
  91.          Xor       AX,AX                     ; Prepare to count params
  92.          Push      AX                        ; Save on stack
  93.          Call      __ParInfo                 ; Get param count
  94.          Add       SP,2                      ; Realign stack
  95.          Or        AX,AX                     ; Zero params?
  96.          JNZ       Test1                     ; If not, continue
  97.          Jmp       Done                      ; Return value = false, go to end
  98.  
  99. Test1:   Mov       AX,1                      ; Prepare to check parameter #1
  100.          Push      AX                        ; Save parameter # on stack
  101.          Call      __ParInfo                 ; Call parameter info routine
  102.          Add       SP,2                      ; Realign stack
  103.          Test      AX,2                      ; Is parameter numeric?
  104.          JNZ       Get1                      ; If so, continue
  105. BadParam:Xor       AX,AX                     ; Set return value to false
  106.          Jmp       Done                      ; Go to end
  107.  
  108. Get1:    Mov       AX,1                      ; Prepare to retrieve parameter #1
  109.          Push      AX                        ; Save parameter # on stack
  110.          Call      __ParNI                   ; Retrieve parameter
  111.          Add       SP,2                      ; Realign stack
  112.  
  113.          Cmp       AX,385                    ; Test highest inkey()
  114.          JG        BadParam                  ; Bad INKEY() value
  115.          Cmp       AX,-39                    ; Test lowest INKEY()
  116.          JL        BadParam                  ; Bad INKEY() value
  117.  
  118. CtrlF1:  Mov       CL,0                      ; Set ASCII value to null
  119.          Cmp       AX,-10                    ; Is Ctrl F1 thru Alt F10?
  120.          JG        F2                        ; If not, check next range
  121.          Neg       AX                        ; Get absolute value of AX
  122.          Add       AL,74                     ; Translate INKEY() to scan code
  123.          Mov       CH,AL                     ; Move scan code to CH
  124.          Jmp       StuffIt                   ; Stuff the keystroke
  125.  
  126. F2:      Or        AX,AX                     ; See if key is F2 thru F10
  127.          JNS       F1                        ; If not, check next range
  128.          Neg       AX                        ; Get absolute value of AX
  129.          Add       AL,59                     ; Translate INKEY() to scan code
  130.          Mov       CH,AL                     ; Move scan code to CH
  131.          Jmp       StuffIt                   ; Stuff the keystroke
  132.  
  133. F1:      Cmp       AX,28                     ; See if key is F1
  134.          JNE       CtrlF                     ; If not, check next key
  135.          Mov       CH,59                     ; Supply scan code for F1
  136.          Jmp       StuffIt                   ; Stuff the keystroke
  137.  
  138. CtrlF:   Cmp       AX,6                      ; See if key is Ctrl F or End
  139.          JNE       CtrlW                     ; If not, check next key
  140.          Mov       CH,79                     ; Supply scan code for End
  141.          Jmp       StuffIt                   ; Stuff the keystroke
  142.  
  143. CtrlW:   Cmp       AX,23                     ; See if key is Ctrl W or Ctrl End
  144.          JNE       CtrlHome                  ; If not, check next key
  145.          Mov       CH,117                    ; Supply scan code for Ctrl End
  146.          Jmp       StuffIt                   ; Stuff the keystroke
  147.  
  148. CtrlHome:Cmp       AX,29                     ; See if key is Ctrl Home or Ctrl]
  149.          JNE       CtrlV                     ; If not, check next key
  150.          Mov       CH,119                    ; Supply scan code for Ctrl Home
  151.          Jmp       StuffIt                   ; Stuff the keystroke
  152.  
  153. CtrlV:   Cmp       AX,22                     ; See if key is Ins or Ctrl V
  154.          JNE       ShiftTab                  ; If not, check next key
  155.          Mov       CH,82                     ; Supply scan code for Ctrl V
  156.          Jmp       StuffIt                   ; Stuff the keystroke
  157.  
  158. ShiftTab:Cmp       AX,271                    ; See if key is Shift Tab
  159.          JNE       CtrlPgDn                  ; If not, check next key
  160.          Mov       CH,15                     ; Supply scan code for Shift Tab
  161.          Jmp       StuffIt                   ; Stuff the keystroke
  162.  
  163. CtrlPgDn:Cmp       AX,30                     ; See if key is Ctrl PgDn
  164.          JNE       CtrlPgUp                  ; If not, check next key
  165.          Mov       CH,118                    ; Supply scan code for Ctrl PgDn
  166.          Jmp       StuffIt                   ; Stuff the keystroke
  167.  
  168. CtrlPgUp:Cmp       AX,31                     ; See if key is Ctrl PgUp
  169.          JNE       AltQ                      ; If not, check next key
  170.          Mov       CH,132                    ; Supply scan code for Ctrl PgUp
  171.          Jmp       StuffIt                   ; Stuff the keystroke
  172.  
  173. AltQ:    Cmp       AX,272                    ; See if key is Alt Q . . .
  174.          JL        ASCII
  175.          Cmp       AX,281                    ; . . . thru Alt P
  176.          JG        AltA
  177.          Mov       CH,AL
  178.          Jmp       StuffIt
  179.  
  180. AltA:    Cmp       AX,286                    ; See if key is Alt A . . .
  181.          JNL       AltL
  182.          Jmp       BadParam
  183. AltL:    Cmp       AX,294                    ; . . . thru Alt L
  184.          JG        AltZ
  185.          Mov       CH,AL
  186.          Jmp       StuffIt
  187.  
  188. AltZ:    Cmp       AX,300                    ; See if key is Alt Z . . .
  189.          JNL       AltM
  190.          Jmp       BadParam
  191. AltM:    Cmp       AX,306                    ; . . . thru Alt M
  192.          JG        Alt1
  193.          Mov       CH,AL
  194.          Mov       CL,0
  195.          Jmp       StuffIt
  196.  
  197. Alt1:    Cmp       AX,376                    ; See if key is Alt 1 . . .
  198.          JNL       AltNum
  199.          Jmp       BadParam
  200. AltNum:  Mov       CH,AL
  201.          Mov       CL,0
  202.          Jmp       StuffIt
  203.  
  204. ASCII:   Or        AH,AH                     ; See if key is plain ASCII
  205.          JZ        Okay
  206.          Jmp       BadParam
  207. Okay:    Mov       CX,AX
  208.  
  209. StuffIt: Push      BP                        ; Save BP
  210.          Mov       BP,SP                     ; Set up stack reference
  211.          Sub       SP,10                     ; Allocate local structure
  212.          Mov       [Word Ptr BP - 10],5      ; Choose keystroke event
  213.          Mov       [Word Ptr BP - 8],0       ; Init flag word to 0
  214.          Mov       [Word Ptr BP - 6],CX      ; Store keystroke in structure
  215.          Mov       [Word Ptr BP - 4],0       ; Init mouse row to 0
  216.          Mov       [Word Ptr BP - 2],0       ; Init mouse col to 0
  217.          Push      SS                        ; Put structure segment on stack
  218.          LEA       AX,[BP - 10]              ; Load structure offset
  219.          Push      AX                        ; Put structure offset on stack
  220.          Mov       AX,3                      ; Post event subfunction code
  221.          Push      AX                        ; Place onto stack
  222.          Call      __evLow                   ; Call internal event handler
  223.          Dec       AX                        ; Convert error code . . .
  224.          Neg       AX                        ; . . . to a logical value
  225.          Mov       SP,BP                     ; Restore stack alignment
  226.          Pop       BP                        ; Restore BP
  227.  
  228. Done:    Push      AX                        ; Save return value on stack
  229.          Call      __RetL                    ; Return it to Clipper app
  230.          Add       SP,2                      ; Realign stack
  231.          Ret
  232. Endp     FT_PutKey
  233. Ends     _NanFor
  234. End
  235.  
  236.  
  237.