Results 1 to 3 of 3

Thread: [RESOLVED] Scroll Locking code and API is to turn on. (I need it to turn off instead)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    222

    Resolved [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
    Last edited by SQLADOman; Jun 16th, 2010 at 03:51 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Scroll Locking code and API is to turn on. (I need it to turn off instead)

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    222

    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.

Posting Permissions

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



Click Here to Expand Forum to Full Width