PC Review


Reply
Thread Tools Rate Thread

Can macro type "vbKeyNumpad5" into a cell - to check for NumLock o

 
 
Steve
Guest
Posts: n/a
 
      14th Aug 2009
I've seen the programming test for NumLock and it appears pretty complicated.
Would it be possible for a macro to simulate pressing the 5 key on the
number pad to see what the result is? If you get a 5, NumLock would be on,
if you get nothing, NumLock would be off.

I have tried this with SendKeys and all I get is 101 > the code for the key.
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      14th Aug 2009
I'm not sure what code you looked at, but I don't think the test for the
NumLock being on or off is *that* complicated. Copy/paste this code into a
Module (Insert/Module from the VB editor's menu bar)...

' *************** START OF CODE ***************
Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long

Private Const VK_NUMLOCK = &H90

Public Function IsNumLockOn() As Boolean
Dim bytKeys(255) As Byte
GetKeyboardState bytKeys(0)
IsNumLockOn = bytKeys(VK_NUMLOCK)
End Function
' *************** END OF CODE ***************

To use it, simple call the IsNumLockOn function... it will return True if
the NumLock is on and False if it is not on.

If IsNumLockOn Then
MsgBox "The NumLock is on!"
Else
MsgBox "The NumLock is not on."
End If

--
Rick (MVP - Excel)


"Steve" <(E-Mail Removed)> wrote in message
news:9FA5D151-645E-48BA-9246-(E-Mail Removed)...
> I've seen the programming test for NumLock and it appears pretty
> complicated.
> Would it be possible for a macro to simulate pressing the 5 key on the
> number pad to see what the result is? If you get a 5, NumLock would be
> on,
> if you get nothing, NumLock would be off.
>
> I have tried this with SendKeys and all I get is 101 > the code for the
> key.


 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      15th Aug 2009
What I found was on the Microsoft site and the programming appeared to be at
least one page long. I'll try what you gave me - Thanks.

"Rick Rothstein" wrote:

> I'm not sure what code you looked at, but I don't think the test for the
> NumLock being on or off is *that* complicated. Copy/paste this code into a
> Module (Insert/Module from the VB editor's menu bar)...
>
> ' *************** START OF CODE ***************
> Private Declare Function GetKeyboardState Lib "user32" _
> (pbKeyState As Byte) As Long
>
> Private Const VK_NUMLOCK = &H90
>
> Public Function IsNumLockOn() As Boolean
> Dim bytKeys(255) As Byte
> GetKeyboardState bytKeys(0)
> IsNumLockOn = bytKeys(VK_NUMLOCK)
> End Function
> ' *************** END OF CODE ***************
>
> To use it, simple call the IsNumLockOn function... it will return True if
> the NumLock is on and False if it is not on.
>
> If IsNumLockOn Then
> MsgBox "The NumLock is on!"
> Else
> MsgBox "The NumLock is not on."
> End If
>
> --
> Rick (MVP - Excel)
>
>
> "Steve" <(E-Mail Removed)> wrote in message
> news:9FA5D151-645E-48BA-9246-(E-Mail Removed)...
> > I've seen the programming test for NumLock and it appears pretty
> > complicated.
> > Would it be possible for a macro to simulate pressing the 5 key on the
> > number pad to see what the result is? If you get a 5, NumLock would be
> > on,
> > if you get nothing, NumLock would be off.
> >
> > I have tried this with SendKeys and all I get is 101 > the code for the
> > key.

>
>

 
Reply With Quote
 
SteveM
Guest
Posts: n/a
 
      18th Aug 2009
I pasted your code in and added this to my programming>

If Not IsNumLockOn Then
SendKeys "{numlock}", True
DoEvents
End If

But nothing happens (it doesn't turn NumLock back on). Does it make a
difference that I am using Excel 2003?

I am using this because I am doing a lot of interaction with another
non-Office program using SendKeys, and occasionally it turns off the NumLock,
even using DoEvents.

"Rick Rothstein" wrote:

> I'm not sure what code you looked at, but I don't think the test for the
> NumLock being on or off is *that* complicated. Copy/paste this code into a
> Module (Insert/Module from the VB editor's menu bar)...
>
> ' *************** START OF CODE ***************
> Private Declare Function GetKeyboardState Lib "user32" _
> (pbKeyState As Byte) As Long
>
> Private Const VK_NUMLOCK = &H90
>
> Public Function IsNumLockOn() As Boolean
> Dim bytKeys(255) As Byte
> GetKeyboardState bytKeys(0)
> IsNumLockOn = bytKeys(VK_NUMLOCK)
> End Function
> ' *************** END OF CODE ***************
>
> To use it, simple call the IsNumLockOn function... it will return True if
> the NumLock is on and False if it is not on.
>
> If IsNumLockOn Then
> MsgBox "The NumLock is on!"
> Else
> MsgBox "The NumLock is not on."
> End If
>
> --
> Rick (MVP - Excel)
>
>
> "Steve" <(E-Mail Removed)> wrote in message
> news:9FA5D151-645E-48BA-9246-(E-Mail Removed)...
> > I've seen the programming test for NumLock and it appears pretty
> > complicated.
> > Would it be possible for a macro to simulate pressing the 5 key on the
> > number pad to see what the result is? If you get a 5, NumLock would be
> > on,
> > if you get nothing, NumLock would be off.
> >
> > I have tried this with SendKeys and all I get is 101 > the code for the
> > key.

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How I can get "Two Hundreds and Twenty" if i type "220" in a cell AHASAN Microsoft Excel Misc 2 29th Sep 2009 01:43 PM
When I type "BVE" in a cell, it automatically chanegs to"BE"..Why =?Utf-8?B?RUxG?= Microsoft Excel Misc 1 28th Jul 2006 07:44 PM
: LOST "Always ask before opening this type of file" check box message Windows XP Internet Explorer 2 4th Sep 2004 11:37 PM
Macro to check "option button" and "check box" John Microsoft Excel Misc 2 16th Aug 2004 08:13 PM
<input id="iPhoto" type="file" size="20" runat="server"> Mark Sandfox Microsoft ASP .NET 1 11th May 2004 02:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:04 PM.