473,378 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Code for Numlock for 64bit

DJRhino1175
221 128KB
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.

Expand|Select|Wrap|Line Numbers
  1. Private Declare Sub keybd_event Lib "user32" ( _
  2. ByVal bVk As Byte, _
  3. ByVal bScan As Byte, _
  4. ByVal dwFlags As Long, _
  5. ByVal dwExtraInfo As Long)
  6. Private Const VK_NUMLOCK = &H90
  7. Private Const KEYEVENTF_KEYUP = &H2
  8. Declare Function GetKeyState Lib "user32.dll" ( _
  9. ByVal nVirtKey As Long) As Integer
  10.  
  11. Sub numon()
  12.      'NUM_Off
  13.     NUM_On
  14. End Sub
  15.  
  16. Sub NUM_TOGGLE()
  17.      'Toggle NUM-Lock key state
  18.     keybd_event VK_NUMLOCK, 1, 0, 0
  19.     keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  20. End Sub
  21.  
  22. Sub NUM_On() 'Turn NUM-Lock on
  23.     If Not (GetKeyState(vbKeyNumlock) = 1) Then
  24.         keybd_event VK_NUMLOCK, 1, 0, 0
  25.         keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  26.     End If
  27. End Sub
  28.  
  29. Sub NUM_Off() 'Turn NUM-Lock off
  30.     If (GetKeyState(vbKeyNumlock) = 1) Then
  31.         keybd_event VK_NUMLOCK, 1, 0, 0
  32.         keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  33.     End If
  34.  
  35. 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.
Mar 28 '19 #1

✓ answered by twinnyfo

Expand|Select|Wrap|Line Numbers
  1. Private Declare PtrSafe Sub keybd_event Lib "user32"

11 3724
twinnyfo
3,653 Expert Mod 2GB
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\.Default\Control Panel\Keyboard
  • Right-click on the “InitialKeyboardIndicators”, 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.
Mar 28 '19 #2
DJRhino1175
221 128KB
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(unfortunately), 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???
Mar 28 '19 #3
twinnyfo
3,653 Expert Mod 2GB
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.
Mar 28 '19 #4
DJRhino1175
221 128KB
Expand|Select|Wrap|Line Numbers
  1. Private Declare Sub keybd_event Lib "user32" ( _
Line 1 is where it hangs up when trying to compile.
Mar 28 '19 #5
DJRhino1175
221 128KB
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.
Mar 28 '19 #6
twinnyfo
3,653 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. Private Declare PtrSafe Sub keybd_event Lib "user32"
Mar 28 '19 #7
DJRhino1175
221 128KB
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.
Mar 28 '19 #8
DJRhino1175
221 128KB
Compiled Code:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Declare PtrSafe Sub keybd_event Lib "user32" ( _
  5. ByVal bVk As Byte, _
  6. ByVal bScan As Byte, _
  7. ByVal dwFlags As Long, _
  8. ByVal dwExtraInfo As Long)
  9. Private Const VK_NUMLOCK = &H90
  10. Private Const KEYEVENTF_KEYUP = &H2
  11. Declare PtrSafe Function GetKeyState Lib "user32.dll" ( _
  12. ByVal nVirtKey As Long) As Integer
  13.  
  14. Sub numon()
  15.      'NUM_Off
  16.     NUM_On
  17. End Sub
  18.  
  19. Sub NUM_TOGGLE()
  20.      'Toggle NUM-Lock key state
  21.     keybd_event VK_NUMLOCK, 1, 0, 0
  22.     keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  23. End Sub
  24.  
  25. Sub NUM_On() 'Turn NUM-Lock on
  26.     If Not (GetKeyState(vbKeyNumlock) = 1) Then
  27.         keybd_event VK_NUMLOCK, 1, 0, 0
  28.         keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  29.     End If
  30. End Sub
  31.  
  32. 'Sub NUM_Off() 'Turn NUM-Lock off
  33. '    If (GetKeyState(vbKeyNumlock) = 1) Then
  34. '        keybd_event VK_NUMLOCK, 1, 0, 0
  35. '        keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  36. '    End If
  37. '
  38. 'End Sub
  39.  
Mar 28 '19 #9
DJRhino1175
221 128KB
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.
Mar 28 '19 #10
twinnyfo
3,653 Expert Mod 2GB
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
Expand|Select|Wrap|Line Numbers
  1. 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.
Mar 28 '19 #11
DJRhino1175
221 128KB
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.
Mar 28 '19 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Christian McArdle | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.os.ms-windows.programmer.64bit This is a formal Request For Discussion (RFD) to create comp.os.ms-windows.programmer.64bit as an unmoderated...
1
by: George | last post by:
Every time I used the Sendkeys command in my application the "Numlock" turned off and I couldn't use the keypad to hit numbers...... The old code was: Private Sub Command1_Click() SendKeys...
5
by: James Kirkup | last post by:
Hello, Does anyone know in code how to turn the NumLock key on in C#? with regards James *** Sent via Developersdex http://www.developersdex.com ***
2
by: Chris | last post by:
can anyone out there tell me how do u check the state of these keys in vb.net? or is there any components in the .NET Framework that supports doing so? any help is appreciated. Thanks.
2
by: Woody Splawn | last post by:
Could someone tell me what code I run to determine if the user's numlock is on? Is there code I can run to set the numlock to on?
5
by: Stan Sainte-Rose | last post by:
Hi I saw a post about numlock but I can't not read it. I would like to check the state of the numlock key and if it's not active, set its status on active. How can I accomplish that in vb ? ...
10
by: lgbjr | last post by:
Hi All, In VB.Net how do I determine if CapsLock is on/off (same for NumLock) and whether the input mode is set to Insert or Overwrite (Insert Key). I just added a status bar to my app, and I...
4
by: legrape | last post by:
I am porting a piece of C code to 64bit on Linux. I am using 64bit integers. It is a floating point intensive code and when I compile (gcc) on 64 bit machine, I don't see any runtime improvement...
3
by: Z.K. | last post by:
I am trying to detect if the Numlock is pressed. I can do it okay with the CapsLock or the ScrLk, but not with NumLock. The code for all three checks is exactly the same, but for some reason...
4
twinnyfo
by: twinnyfo | last post by:
OK Race fans, here's a whacky one: In a separate module, I have these declarations: Option Compare Database Option Explicit Public Declare Function GetTickCount Lib "kernel32" () As Long...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.