CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: NumLock Status

  1. #1
    Join Date
    May 2002
    Location
    Madrid - Spain
    Posts
    78

    Arrow NumLock Status

    How can I set the NumLock status to ON in a C++ program?
    Is there any System Call to do it?

    Thanks.

  2. #2
    Join Date
    May 2002
    Location
    United Kingdom
    Posts
    13
    This could help in VC
    http://www.codeguru.com/misc/control...ock_keys.shtml

    I also remember doing this using Assembly language in C via some keyboard interrrupt. Don't remember which interrupt is for keyboard.

    Cheers
    V

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: NumLock Status

    Originally posted by sarambur
    How can I set the NumLock status to ON in a C++ program?
    Is there any System Call to do it?

    Thanks.
    In standard C++, there is no function call to get the status of the numlock. You have to rely on what your operating system provides, and each operating system will use different methods.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    May 2002
    Location
    United Kingdom
    Posts
    13
    Yeaa.. In C++ there is no function that allows you to set/get the status of NUMLOCK/CAPSLOCK key.

    So whatever the OS is , in C++ you can set/get the status of these keys using BIOS calls.

    You will have to find a function under Int 9 (Keyboard BIOS interrupt) which allows you to set/get values of these keys.

    Cheers
    V

  5. #5
    Join Date
    May 2002
    Location
    Madrid - Spain
    Posts
    78
    Code:
    int  ReqdNumLockState = 0x0001;
    
    
    if( (GetKeyState( VK_NUMLOCK ) & 0x0001) != ReqdNumLockState )
    {
      //Ponemos el NumLock a ON, para que se pueda escribir con el numpad directamente.
      keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
      keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY |   KEYEVENTF_KEYUP, 0 );
    }
    finally I have used this piece of code.
    I havent tested it yet, and I will post if it works or not in about 5 minutes (for anyone who wants to know, of course).

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449
    You also need to post what Windows OS this worked on. This forum is not a Windows-only forum.

    Regards,

    Paul McKenzie

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

Featured