home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / articles / vbbultn / source / keysnd.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-03-01  |  2.8 KB  |  77 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Key Send"
  4.    ClientHeight    =   1845
  5.    ClientLeft      =   1170
  6.    ClientTop       =   1545
  7.    ClientWidth     =   2715
  8.    Height          =   2280
  9.    Icon            =   KEYSND.FRX:0000
  10.    Left            =   1095
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   1845
  13.    ScaleWidth      =   2715
  14.    Top             =   1185
  15.    Width           =   2865
  16.    Begin ccSubClass SubClass1 
  17.       Left            =   600
  18.       Messages        =   KEYSND.FRX:0302
  19.       Top             =   1320
  20.    End
  21.    Begin ccHookKbd HookKbd1 
  22.       Keys            =   KEYSND.FRX:0706
  23.       Left            =   120
  24.       Monitor         =   1  'All Tasks
  25.       Top             =   1320
  26.    End
  27.    Begin Label Label1 
  28.       Caption         =   "While this program is running, the backslash key puts the letter to the left of the cursor into the clipboard.  See keysnd.txt."
  29.       Height          =   1095
  30.       Left            =   120
  31.       TabIndex        =   0
  32.       Top             =   0
  33.       Width           =   2535
  34.    End
  35. Sub HookKbd1_KbdHook (keycode As Integer, keystate As Long, shiftstate As Integer, discard As Integer)
  36.     ' The SbcKbd control is set to intercept the
  37.     ' backslash ("\") key.
  38.     ' First, make sure the key is discarded.
  39.     discard = True
  40.     ' SbcKbd fires events when the key is pressed and
  41.     ' when the key is released.  Ignore any event caused
  42.     ' by the key being released.
  43.     If keystate And &H80000000 Then GoTo Bye:
  44.     ' There might be multiple events per keypress.  Turn
  45.     ' off the SbcKbd control while one event is handled.
  46.     HookKbd1.Enabled = False
  47.     ' Perform the correct action according to which key
  48.     ' was pressed.
  49.     Select Case keycode
  50.     Case 220   ' the keycode for backslash
  51.         ' The actual act of copying the last key into
  52.         ' the clipboard takes too long to be done here.
  53.         ' Instead, the Sbc PostEvent property is set,
  54.         ' telling the Sbc control to send itself a
  55.         ' delayed message.  It will be safe to do the
  56.         ' time intensive stuff then.
  57.         SubClass1.PostEvent = 1
  58.     End Select
  59. End Sub
  60. Sub SubClass1_DelayedEvent (lvalue As Long)
  61.     ' Here is where the time-intensive part of the response
  62.     ' to a message can be implemented.
  63.     ' First, check what value was put into the PostEvent
  64.     ' message, and react accordingly.
  65.     If (lvalue = 1) Then
  66.     ' Select the character to highlight using the
  67.     ' standard Windows keyboard shortcut.
  68.     SendKeys "+{left 1}"
  69.     ' Copy selected text to clipboard using another
  70.     ' standard Windows keyboard shortcut.
  71.     SendKeys "^c"
  72.     ' Turn the SbcKbd control back on, now that we are
  73.     ' finished here.
  74.     HookKbd1.Enabled = True
  75.     End If
  76. End Sub
  77.