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 / capslock.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-02-09  |  4.0 KB  |  114 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Handling Caps Lock"
  4.    ClientHeight    =   3945
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   3810
  8.    Height          =   4350
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3945
  12.    ScaleWidth      =   3810
  13.    Top             =   1140
  14.    Width           =   3930
  15.    Begin OptionButton Toggle 
  16.       Height          =   195
  17.       Left            =   3060
  18.       TabIndex        =   5
  19.       Top             =   810
  20.       Width           =   195
  21.    End
  22.    Begin CommandButton Command1 
  23.       Caption         =   "Close"
  24.       Height          =   525
  25.       Left            =   1320
  26.       TabIndex        =   2
  27.       Top             =   3330
  28.       Width           =   1245
  29.    End
  30.    Begin CheckBox IgnoreCapsLock 
  31.       Caption         =   "Ignore CAPS LOCK"
  32.       Height          =   255
  33.       Left            =   810
  34.       TabIndex        =   1
  35.       Top             =   780
  36.       Value           =   1  'Checked
  37.       Width           =   1935
  38.    End
  39.    Begin ccHookKbd HookKbd1 
  40.       Keys            =   CAPSLOCK.FRX:0000
  41.       Left            =   150
  42.       Top             =   3330
  43.    End
  44.    Begin Label Label3 
  45.       Caption         =   "If Ignore CAPS LOCK is NOT Checked. Then the only the value of the shiftstate parameter needs to be checked. If CAPS LOCK is ON and the Shift key is hit, it will result in a shiftstate value of 0."
  46.       Height          =   1035
  47.       Left            =   150
  48.       TabIndex        =   4
  49.       Top             =   2160
  50.       Width           =   3585
  51.    End
  52.    Begin Label Label2 
  53.       Caption         =   "If Ignore CAPS LOCK is Checked. Then the physical Shift Key must not be hit with F4, and the physical Shift Key must be hit with F3 in order to trigger the Beep."
  54.       Height          =   855
  55.       Left            =   150
  56.       TabIndex        =   3
  57.       Top             =   1110
  58.       Width           =   3585
  59.    End
  60.    Begin Label Label1 
  61.       Caption         =   "Hot Keys are F4 and Shift-F3, they will cause a Beep and toggle the state of the option button."
  62.       Height          =   585
  63.       Left            =   480
  64.       TabIndex        =   0
  65.       Top             =   120
  66.       Width           =   2925
  67.    End
  68. Option Explicit
  69. Declare Function GetKeyState% Lib "user" (ByVal vkey%)
  70. Const VK_CAPITAL = &H14
  71. Const VK_F3 = &H72
  72. Const VK_F4 = &H73
  73. Sub Command1_Click ()
  74. Unload Me
  75. End Sub
  76. Sub HookKbd1_KbdHook (keycode As Integer, keystate As Long, shiftstate As Integer, discard As Integer)
  77.     Dim capslockstate%
  78.     'Trigger on the Key Down, ignore Key Up
  79.     If keystate And &H80000000 Then Exit Sub
  80.     capslockstate% = GetKeyState(VK_CAPITAL)
  81.     Select Case keycode
  82.         Case VK_F3  'Shift-F3 will cause a beep
  83.             If IgnoreCapsLock.Value Then
  84.                 ' Do an exclusive Or on the Caps Lock state and
  85.                 ' the shiftstate parameter - if True then indicates
  86.                 ' that the shift key was physically hit.
  87.                 If (capslockstate% Xor shiftstate) Then
  88.                     Beep
  89.                     Toggle.Value = Not Toggle.Value
  90.                 End If
  91.             Else
  92.                 If shiftstate Then
  93.                     Beep
  94.                     Toggle.Value = Not Toggle.Value
  95.                 End If
  96.             End If
  97.         Case VK_F4  'F4 will cause a beep
  98.             If IgnoreCapsLock.Value Then
  99.                 ' Do an exclusive Or on the Caps Lock state and
  100.                 ' the shiftstate parameter - if False then indicates
  101.                 ' that the shift key was NOT physically hit.
  102.                 If (capslockstate% Xor shiftstate) = 0 Then
  103.                     Beep
  104.                     Toggle.Value = Not Toggle.Value
  105.                 End If
  106.             Else
  107.                 If shiftstate = 0 Then
  108.                     Beep
  109.                     Toggle.Value = Not Toggle.Value
  110.                 End If
  111.             End If
  112.     End Select
  113. End Sub
  114.