Code for Numlock for 64bit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DJRhino1175
    New Member
    • Aug 2017
    • 221

    Code for Numlock for 64bit

    I have VBA code to make sure the numlocks are on, but we I try to compile it it tells me it needs to be in 64bit.

    Code:
    Private Declare Sub keybd_event Lib "user32" ( _
    ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, _
    ByVal dwExtraInfo As Long)
    Private Const VK_NUMLOCK = &H90
    Private Const KEYEVENTF_KEYUP = &H2
    Declare Function GetKeyState Lib "user32.dll" ( _
    ByVal nVirtKey As Long) As Integer
    
    Sub numon()
         'NUM_Off
        NUM_On
    End Sub
    
    Sub NUM_TOGGLE()
         'Toggle NUM-Lock key state
        keybd_event VK_NUMLOCK, 1, 0, 0
        keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
    End Sub
    
    Sub NUM_On() 'Turn NUM-Lock on
        If Not (GetKeyState(vbKeyNumlock) = 1) Then
            keybd_event VK_NUMLOCK, 1, 0, 0
            keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
        End If
    End Sub
    
    Sub NUM_Off() 'Turn NUM-Lock off
        If (GetKeyState(vbKeyNumlock) = 1) Then
            keybd_event VK_NUMLOCK, 1, 0, 0
            keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
        End If
    
    End Sub
    I do have 64bit, and I want to add this to all my database as we use the numpad a lot. We are so use to the numlocks being on all the time, but since we upgraded all our PC's to Win 10, the numlock always turns off.

    Thanks a million for all your help.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    DJ,

    Actually, what you really want to do is change the num lock in the system settings. This is not a Win 10 thing, it is a Network System Administrator thing, in which, for some absolutely unknown reason, they are changing the system registry to default the system to Num Lock Off.
    • Press Win + R and type in Regedit
    • Navigate to registry key HKEY_USERS\.Def ault\Control Panel\Keyboard
    • Right-click on the “InitialKeyboar dIndicators”, select Modify and change Value data to 2.
    • Exit and Save the Registry.


    This may (probably) need to be done by an administrator.

    There are ways to "trick" the Num Lock to switch, but my experiences with it have have been and miss. But, I admit I haven't tried it with Win 10, so that may be more stable--but again, the above does not answer your specific question about a 64-bit key for that value.

    Concerning converting it to 64-bit, an initial guess would be add two leading zeroes to your value? But that is purely speculation.

    Comment

    • DJRhino1175
      New Member
      • Aug 2017
      • 221

      #3
      Our system is locked out by our company IT. If I do it through VBA, it will fix it for everyone that uses one of my Databases. I only have user rights in my company(unfortu nately), so makes it very difficult do fix issues when they arise....

      But thanks for your reply. I even did research on what you put and I guess the solution you put forth isn't a 100% fix for Win10.

      When will microsoft get things right???

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3653

        #4
        So, when you compile your DB, it hangs on Line 6 above?

        We've got 64-bit at work, too, and I've had no issues with compiling--and I use your same function for some other things I do. I am having no issues with toggling the Num Lock.

        Comment

        • DJRhino1175
          New Member
          • Aug 2017
          • 221

          #5
          Code:
          Private Declare Sub keybd_event Lib "user32" ( _
          Line 1 is where it hangs up when trying to compile.

          Comment

          • DJRhino1175
            New Member
            • Aug 2017
            • 221

            #6
            Here is the error that pops up

            Compile Error:
            The code in this project must be updated for use on64-bit systems. Please review and update Declare statements and then mark them with PtrSafe attribute.
            Last edited by DJRhino1175; Mar 28 '19, 02:44 PM. Reason: Numlock was off...

            Comment

            • twinnyfo
              Recognized Expert Moderator Specialist
              • Nov 2011
              • 3653

              #7
              Code:
              Private Declare [B][I][U]PtrSafe[/U][/I][/B] Sub keybd_event Lib "user32"

              Comment

              • DJRhino1175
                New Member
                • Aug 2017
                • 221

                #8
                That did it, need it in 2 spots, but got it to compile. Now to test the code to make sure it works. I put this into a Module, I'm not 100% sure if this was the right place to put it.

                Comment

                • DJRhino1175
                  New Member
                  • Aug 2017
                  • 221

                  #9
                  Compiled Code:

                  Code:
                  Option Compare Database
                  Option Explicit
                  
                  Private Declare PtrSafe Sub keybd_event Lib "user32" ( _
                  ByVal bVk As Byte, _
                  ByVal bScan As Byte, _
                  ByVal dwFlags As Long, _
                  ByVal dwExtraInfo As Long)
                  Private Const VK_NUMLOCK = &H90
                  Private Const KEYEVENTF_KEYUP = &H2
                  Declare PtrSafe Function GetKeyState Lib "user32.dll" ( _
                  ByVal nVirtKey As Long) As Integer
                  
                  Sub numon()
                       'NUM_Off
                      NUM_On
                  End Sub
                  
                  Sub NUM_TOGGLE()
                       'Toggle NUM-Lock key state
                      keybd_event VK_NUMLOCK, 1, 0, 0
                      keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
                  End Sub
                  
                  Sub NUM_On() 'Turn NUM-Lock on
                      If Not (GetKeyState(vbKeyNumlock) = 1) Then
                          keybd_event VK_NUMLOCK, 1, 0, 0
                          keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
                      End If
                  End Sub
                  
                  'Sub NUM_Off() 'Turn NUM-Lock off
                  '    If (GetKeyState(vbKeyNumlock) = 1) Then
                  '        keybd_event VK_NUMLOCK, 1, 0, 0
                  '        keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
                  '    End If
                  '
                  'End Sub

                  Comment

                  • DJRhino1175
                    New Member
                    • Aug 2017
                    • 221

                    #10
                    Trying to run this code, but cannot get it to trigger through an Autoexec macro(I know bad)

                    Would I put this in "On Open" event of the form? Would I need to put this onto every form as to make sure it runs for every form? Is there a way to run this a different way? Should I just use one of the subs and if so how would I call this out in my database?

                    Sorry for the multiple questions, but this is new territory for me.

                    Comment

                    • twinnyfo
                      Recognized Expert Moderator Specialist
                      • Nov 2011
                      • 3653

                      #11
                      That's why I have a "Splash" form on my databases. I can accomplish whatever I want while that form is showing. Then, when folks open the DB, just call
                      Code:
                      Num_On
                      . Of course, you would declare these procedures to be public in your module so that you could call it from anywhere in the DB.

                      Comment

                      • DJRhino1175
                        New Member
                        • Aug 2017
                        • 221

                        #12
                        It works. I made a splash screen, added to the "on load" event.
                        Now to play with it a little.

                        Thanks a million again for your help.

                        Comment

                        Working...