Sign in with Microsoft
Sign in or create an account.
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.


SetKeyboardState ()的檔會正確指出您無法使用這個 API 來切換 NUM LOCK、CAPS LOCK 和 SCROLL LOCK 鍵。您可以使用 keybd_event ()來切換 [Windows NT] 下的 [NUM LOCK]、[大寫鎖定] 和 [滾動鎖定] 鍵。 相同的技術可在 Windows 95 下切換大寫鎖定和滾動鎖,但不會對 NUM LOCK 起作用。


下列範例程式會將 NUM LOCK 燈開啟(如果它是關閉狀態)。 在此處定義的 SetNumLock 函數會使用 keybd_event ()與虛擬鍵 VK_NUMLOCK 來類比 NUM LOCK 鍵。 它會採用一個布林值來指示光線應該是關閉(FALSE)還是開啟(TRUE)。使用相同的技術,就可以使用 CAPS LOCK 鍵(VK_CAPITAL)和滾動鎖定鍵(VK_SCROLL)。


   /* Compile options needed:   */    #include <windows.h>   void SetNumLock( BOOL bState )   {      BYTE keyState[256];      GetKeyboardState((LPBYTE)&keyState);      if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||          (!bState && (keyState[VK_NUMLOCK] & 1)) )      {      // Simulate a key press         keybd_event( VK_NUMLOCK,                      0x45,                      KEYEVENTF_EXTENDEDKEY | 0,                      0 );      // Simulate a key release         keybd_event( VK_NUMLOCK,                      0x45,                      KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,                      0);      }   }   void main()   {      SetNumLock( TRUE );   }

Need more help?

Want more options?



Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!