home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l408 / 2.img / EXAMPLES.EXE / EXAMPLES / KEYBUFF / KEYBUFF.SUB < prev    next >
Encoding:
Text File  |  1991-05-04  |  2.6 KB  |  96 lines

  1. DefInt A-Z
  2. ' DefaultElements is the number of lines this
  3. ' module will remember if you don't call the
  4. ' MhInitKeyBuff routine.
  5. Const DefaultElements = 50
  6. Dim MaxElements As Integer
  7. ' So we don't add the stuffed keys back to the buffer
  8. Dim JustStuffedOne As Integer
  9.  
  10. Sub MhInitKeyBuff (Elements%)
  11.  
  12.     ' Call this sub to initialize or re-intialize
  13.     ' the buffer. Note that re-initializing it will
  14.     ' cause you to lose the existing contents.
  15.     MaxElements = Elements
  16.     MhClearKeyBuff
  17.     
  18. End Sub
  19.  
  20. Sub MhStoreText (TextLine$)
  21.  
  22.     ' Call this sub to store one command line for later
  23.     ' recall.
  24.     Dim I As Integer
  25.  
  26.     If Len(TextLine$) Then  ' Only store if some length
  27.         ' If you didn't call the init routine, we need to
  28.         ' use our defaults.
  29.         If MaxElements = 0 Then
  30.            MaxElements = DefaultElements
  31.         End If
  32.         ' We wouldn't want to add the same
  33.         ' text back to the buffer, right?
  34.         If JustStuffedOne Then
  35.            SetFlags 0
  36.            Exit Sub
  37.         End If
  38.         ' See if your text is already in the lisbox
  39.         For I = 0 To KeyBuff.KeyBuffList.ListCount
  40.             ' If so, get out gracefully
  41.             If KeyBuff.KeyBuffList.List(I) = TextLine$ Then
  42.                Exit Sub
  43.             End If
  44.         Next
  45.         If KeyBuff.KeyBuffList.ListCount > MaxElements Then
  46.            ' Remove one element
  47.            KeyBuff.KeyBuffList.RemoveItem 0
  48.         End If
  49.         ' Add the item to the listbox
  50.         KeyBuff.KeyBuffList.AddItem TextLine$
  51.         ' Set the pointer
  52.         KeyBuff.KeyBuffList.ListIndex = KeyBuff.KeyBuffList.ListCount - 1
  53.     End If
  54.  
  55. End Sub
  56.  
  57. Sub MhKeyBuff ()
  58.  
  59.     ' When you Call this procedure
  60.     ' the listbox becomes visible and
  61.     ' the user can select a line of text
  62.     ' that he wants plugged into the
  63.     ' keyboard buffer.
  64.     Dim ExitCode As Integer
  65.  
  66.     KeyBuff.ExitSignal.Text = "0"  ' Exit code indicator
  67.                                     ' 1 = Exit with paste
  68.                                     ' 2 = Exit without paste
  69.     KeyBuff.KickStart.Value = -1   ' Click the hidden button
  70.     Do
  71.         X% = DoEvents()  ' Allow background processes
  72.         ExitCode = Val(KeyBuff.ExitSignal.Text)
  73.     Loop Until ExitCode
  74.     KeyBuff.Hide
  75.     If ExitCode = 1 Then
  76.        SendKeys KeyBuff.KeyBuffList.List(KeyBuff.KeyBuffList.ListIndex)
  77.        X% = DoEvents()
  78.     End If
  79.  
  80. End Sub
  81.  
  82. Sub SetFlags (Condition%)
  83.  
  84.     JustStuffedOne = Condition%
  85.  
  86. End Sub
  87.  
  88. Sub MhClearKeyBuff ()
  89.  
  90.     Do While KeyBuff.KeyBuffList.ListCount
  91.        KeyBuff.KeyBuffList.RemoveItem 0
  92.     Loop
  93.  
  94. End Sub
  95.  
  96.