473,397 Members | 2,099 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,397 software developers and data experts.

SendKeys turns off NumLock

twinnyfo
3,653 Expert Mod 2GB
OK Race fans, here's a whacky one:

In a separate module, I have these declarations:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Declare Function GetTickCount Lib "kernel32" () As Long
  5. Public Declare Function GetLastInputInfo Lib "user32" (pLII As Any) As Long
  6.  
  7. Private Type LastInputInformation
  8.     cbSize As Long
  9.     dwTime As Long
  10. End Type
  11.  
  12. Public Function GetUsersIdleTime() As Long
  13.     Dim LII As LastInputInformation
  14.     LII.cbSize = Len(LII)
  15.     Call GetLastInputInfo(LII)
  16.     GetUsersIdleTime = FormatNumber((GetTickCount() - LII.dwTime) / 1000, 2)
  17. End Function
  18.  
These allow me to check whether someone has been using their machine and how long the system has been idle.

In the Timer Event of a form, set to 60,000 (60 seconds), I have this code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer()
  2. On Error GoTo EH
  3.     If GetUsersIdleTime() >= 59 Then
  4.         SendKeys "^"
  5.     End If
  6.     Exit Sub
  7. EH:
  8.     MsgBox "There was an error with the Timer!  Please contact your Database Administrator.", vbCritical, "Error!"
  9.     Exit Sub
  10. End Sub
  11.  
What this does, and it works rather well, is it checks to see if the user has been active on the computer within the last 59 seconds. If not, it "types" a keystroke, in this case, it simulates hitting and releasing the Ctrl-Key. This prevents our screen savers from activating, thus breaking our network connections with the database. Our users will often have to review documents while the DB sits idle. This saves a lot of headaches, and some of you may be familiar with some of my recent posts conerning this.

Here is the issue: When I open this form, when the SendKeys statement activates, the NumLock status automatically turns OFF (it never turns itself back on, but must be turned on manually). This is a real pain, because this form uses the SSN of a person to search, so we often don't realize the NumLock is off until after we start keying in the number. (I have also simulated the Shift Key--"+" with similar results).

This is not a huge deal, but it is really annoying. This is the only thing that has changed on our machines, and it MUST be the form, because when I've opened the form and just let it sit, the NumLock turns off at exactly 60 seconds! (although not all the time--even stranger!)

Any thoughts or ideas on why this is happening and a way to prevent it from happening? Perhaps checking and resetting NumLock status--which I don't know how to do....

I am open to any ideas.

Thanks!
Oct 4 '12 #1

✓ answered by neelsfer

Maybe this will help if i am not missing the plot here.. I have the following code in a module, and call it with numon
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Declare Sub keybd_event Lib "user32" ( _
  4. ByVal bVk As Byte, _
  5. ByVal bScan As Byte, _
  6. ByVal dwFlags As Long, _
  7. ByVal dwExtraInfo As Long)
  8. Private Const VK_NUMLOCK = &H90
  9. Private Const KEYEVENTF_KEYUP = &H2
  10. Declare Function GetKeyState Lib "user32.dll" ( _
  11. ByVal nVirtKey As Long) As Integer
  12.  
  13. Sub numon()
  14.      'NUM_Off
  15.     NUM_On
  16. End Sub
  17.  
  18. Sub NUM_TOGGLE()
  19.      'Toggle NUM-Lock key state
  20.     keybd_event VK_NUMLOCK, 1, 0, 0
  21.     keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  22. End Sub
  23.  
  24. Sub NUM_On() 'Turn NUM-Lock on
  25.     If Not (GetKeyState(vbKeyNumlock) = 1) Then
  26.         keybd_event VK_NUMLOCK, 1, 0, 0
  27.         keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  28.     End If
  29. End Sub
  30.  
  31. Sub NUM_Off() 'Turn NUM-Lock off
  32.     If (GetKeyState(vbKeyNumlock) = 1) Then
  33.         keybd_event VK_NUMLOCK, 1, 0, 0
  34.         keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  35.     End If
  36.  
  37. End Sub

4 16064
neelsfer
547 512MB
Maybe this will help if i am not missing the plot here.. I have the following code in a module, and call it with numon
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Declare Sub keybd_event Lib "user32" ( _
  4. ByVal bVk As Byte, _
  5. ByVal bScan As Byte, _
  6. ByVal dwFlags As Long, _
  7. ByVal dwExtraInfo As Long)
  8. Private Const VK_NUMLOCK = &H90
  9. Private Const KEYEVENTF_KEYUP = &H2
  10. Declare Function GetKeyState Lib "user32.dll" ( _
  11. ByVal nVirtKey As Long) As Integer
  12.  
  13. Sub numon()
  14.      'NUM_Off
  15.     NUM_On
  16. End Sub
  17.  
  18. Sub NUM_TOGGLE()
  19.      'Toggle NUM-Lock key state
  20.     keybd_event VK_NUMLOCK, 1, 0, 0
  21.     keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  22. End Sub
  23.  
  24. Sub NUM_On() 'Turn NUM-Lock on
  25.     If Not (GetKeyState(vbKeyNumlock) = 1) Then
  26.         keybd_event VK_NUMLOCK, 1, 0, 0
  27.         keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  28.     End If
  29. End Sub
  30.  
  31. Sub NUM_Off() 'Turn NUM-Lock off
  32.     If (GetKeyState(vbKeyNumlock) = 1) Then
  33.         keybd_event VK_NUMLOCK, 1, 0, 0
  34.         keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
  35.     End If
  36.  
  37. End Sub
Oct 4 '12 #2
twinnyfo
3,653 Expert Mod 2GB
neels,

Thanks for the code.... I will give it a try and see how it works!
Oct 4 '12 #3
twinnyfo
3,653 Expert Mod 2GB
Neels,

Took a few very minor tweaks to add this code to a public module, then I reset the idle time, and use your code to make sure the NumLock is currently on. Success!

Thanks much!
Oct 4 '12 #4
neelsfer
547 512MB
Glad i could help somebody, after having received so much help on this site!
Oct 4 '12 #5

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

Similar topics

2
by: RBohannon | last post by:
I need to create a report in MS Word populated with data from A2K. I have been asked to create the report in Word so that parts of it can be edited as necessary later. The data in the report are...
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 ? ...
2
by: Phil Galey | last post by:
I have an application written in VB.NET, running on Windows 2000 SP 3. It uses a process object and AppActivate, followed by SendKeys commands, to control a running QuarkXPress application. On...
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...
5
by: Joe S | last post by:
I have been searching all over for how to use SendKeys to send Keys.RControlKey. I've tried all manner of byte conversions and just can't get it to work. Pity there is no {RCONTROL} defined...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.