The original version of this code turned on scroll locking, but I need to it turn it off if it is on.
I made the changes that I commented in blue, and it works as I wanted, but I want to have one of you experts look to see if you spot any other changes that should be made.
Thanks
http://support.microsoft.com/kb/177674
Code:Private Type OSVERSIONINFO ' Declare Type for API call dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 ' Maintenance string for PSS usage End Type ' API declarations Private Declare Function GetVersionEx Lib "kernel32" _ Alias "GetVersionExA" _ (lpVersionInformation As OSVERSIONINFO) As Long 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 GetKeyboardState Lib "user32" _ (pbKeyState As Byte) As Long Private Declare Function SetKeyboardState Lib "user32" _ (lppbKeyState As Byte) As Long ' Constant declarations Const VK_SCROLL = &H91 Const KEYEVENTF_EXTENDEDKEY = &H1 Const KEYEVENTF_KEYUP = &H2 Const VER_PLATFORM_WIN32_NT = 2 Const VER_PLATFORM_WIN32_WINDOWS = 1 Sub ScrollLock() On Error Resume Next Dim o As OSVERSIONINFO Dim ScrollLockState As Boolean o.dwOSVersionInfoSize = Len(o) GetVersionEx o Dim keys(0 To 255) As Byte GetKeyboardState keys(0) ''' ScrollLock handling ScrollLockState = keys(VK_SCROLL) If ScrollLockState <> False Then ' changed from True to False If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '=== Win95/98 keys(VK_SCROLL) = 0 ' changed from 1 to 0 SetKeyboardState keys(1) ' changed from 0 to 1 ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then '=== WinNT '''Simulate Key Press keybd_event VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0 '''Simulate Key Release keybd_event VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY _ Or KEYEVENTF_KEYUP, 0 End If End If End Sub




Reply With Quote