Results 1 to 7 of 7

Thread: How can I know if NumLock is On Or Off

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    How can I know if NumLock is On Or Off

    Hi

    How can I know if NumLock is On Or Off

    And how can change the status of the NumLock
    From my program to On Or Off

    Please send me a small example
    The code:
    SendKeys.Send("{NUMLOCK}")
    not work always !!!

    Have a nice day

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    The reason setting NUM LOCK doesn't always work is that it is only temporarily set until SendKeys yields to another process.

    You can use an API to permanently set NUM LOCK. MSDN has an article on this. Search for "HOWTO: Toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK Keys" and PSS ID Number: 177674.
    This world is not my home. I'm just passing through.

  3. #3
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    To get the state of the NumLock key try this:

    VB Code:
    1. Public Declare Auto Function GetKeyState Lib "user32" _
    2.                                         (ByVal nVirtKey As Integer) As Short
    3.  
    4.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    5.         TextBox1.Text = GetKeyState(144)
    6.     End Sub
    This world is not my home. I'm just passing through.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224
    Hi,


    Ok, very small and nice

    Now how can change the status of the NumLock
    From my program to On Or Off

  5. #5
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    Doesn't the first of my previous two replies give you enough information for this?
    This world is not my home. I'm just passing through.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224
    Hi,

    I download the:
    "HOWTO: Toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK Keys"

    It is for vb6

    I try it in vb.net and i not able to convert it to vb.net

    if you want to see it, i uploade it

    Thanks
    Attached Files Attached Files

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224
    Hi,

    Ok, I got it

    Declare Function GetKeyboardState Lib "user32" _
    Alias "GetKeyboardState" (ByVal pbKeyState() As Byte) As Long

    Private Sub Button1_Click...

    Dim state(256) As Byte
    GetKeyboardState(state)
    If state(Keys.NumLock) = 1 Then
    MsgBox("true") 'Only for test
    SendKeys.Send("{NUMLOCK}")
    ' My code
    SendKeys.Send("{NUMLOCK}")
    Else
    MsgBox("false") 'Only for test
    ' My code
    End If

    End Sub

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