home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / NFSRC305.ZIP / ASM / PUTKEY.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-01  |  10.3 KB  |  233 lines

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