BUG: GP Fault When KEYSTAT.VBX Used in Two or More Apps (121681)



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition for Windows 3.0

This article was previously published under Q121681

SYMPTOMS

When the KEYSTAT.VBX control is used in more than one application, and the parent window is minimized, the application causes a general protection (GP) fault.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft product listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

WORKAROUND

To work around this problem, use the Windows API GetKeyboardState function directly as in the following example:

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. Add the following code to the (general) (declarations) section
       Declare Sub GetKeyboardState Lib "User" (ByVal lpKeyState As String)
       Const VK_SHIFT = &H10
       Const VK_CAPITAL = &H14
       Const VK_NUMLOCK = &H90
    						
  3. Place a command button (Command1) on Form1, and add the following code to the Command1 Click event:
       Sub Command1_Click ()
          Dim keys As String
          keys = Space$(256)
          GetKeyboardState keys
          If &H1 = (Asc(Mid(keys, VK_CAPITAL + 1, 1)) And &H1) Then
             Debug.Print "Caps lock"
          Else
             Debug.Print "non caps"
          End If
          If &H1 = (Asc(Mid(keys, VK_NUMLOCK + 1, 1)) And &H1) Then
             Debug.Print "Num lock"
          Else
             Debug.Print "non lock"
          End If
       End Sub
    						
  4. Run the application.

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:kbbug KB121681