[RESOLVED] Scroll Locking code and API is to turn on. (I need it to turn off instead)
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
Re: Scroll Locking code and API is to turn on. (I need it to turn off instead)
Quote:
keys(VK_SCROLL) = 0 ' changed from 1 to 0
SetKeyboardState keys(1) ' changed from 0 to 1
afaik changing those lines would be incorrect, and are only effected in win 9x anyway
see if this helps you at all
http://vbnet.mvps.org/index.html?cod...capslocknt.htm
Re: Scroll Locking code and API is to turn on. (I need it to turn off instead)
Thanks westconn1
I certainly should have noticed that part was for win 95/98.
The link you provided I am sure I will find helpful some time later when I have time to sort through it to adapt it to my need, but for now I just modified the code I have. - I changed ScrollLockState <> True to ScrollLockState <> False and removed the 95/98 part of the code, changed the Elseif to an If for the NT part of it and am calling the macro in the selection change event. It seems to be working fine.