Consulting

Results 1 to 12 of 12

Thread: SendKeyys command turns off Numlock

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    Have you tried DoEvents after the first one? See last sub...

    Const NumLock_On = &H20
    Const ScrollLock_On = &H40
    Const CapsLock_On = &H80
    Const vk_Scroll = &H91
    
    
    Private Declare Sub keybd_event Lib "user32" _
      (ByVal bVk As Byte, ByVal bScan As Byte, _
      ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
    
    Private Declare Function GetKeyState Lib "user32" _
      (ByVal nVirtKey As Long) As Long
    
    
    Sub KeyLock(myKey As String, State As Boolean)
    'State=True means to press key if state is off
    'myKey must be: Num, Scroll, or Caps as String type.
    
    
    Select Case True
      Case myKey Like "Num"
        If State <> CBool(GetKeyState(vbKeyNumlock)) Then PressKey (vbKeyNumlock)
      Case myKey Like "Scroll"
        If State <> CBool(GetKeyState(vk_Scroll)) Then PressKey (vk_Scroll)
      Case myKey Like "Caps"
        If State <> CBool(GetKeyState(vbKeyCapital)) Then PressKey (vbKeyCapital)
      Case Else
        'Nothing to do
    End Select
    End Sub
    
    
    Sub PressKey(theKey As Long)
      keybd_event theKey, 0, 0, 0 'press key
      keybd_event theKey, 0, &H2, 0 'release key
    End Sub
    
    
    Sub NumsOn()
      KeyLock "Num", True
    End Sub
    
    
    Sub NumsOff()
      KeyLock "Num", False
    End Sub
    
    
    Sub CapsOn()
      KeyLock "Caps", True
    End Sub
    
    
    Sub CapsOff()
      KeyLock "Caps", False
    End Sub
    
    
    Sub ScrollOn()
      KeyLock "Scroll", True
    End Sub
    
    
    Sub ScrollOff()
      KeyLock "Scroll", False
    End Sub
    
    
    Sub NumLockOnTwiceTest()
      KeyLock "Num", True
      DoEvents
      KeyLock "Num", True
    End Sub
    Last edited by Kenneth Hobs; 06-24-2020 at 08:05 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •