1. 程式人生 > >虛擬按鍵的判斷方法

虛擬按鍵的判斷方法

問題描述:

判斷CapsLock,Alt,Ctrl,Shift是否被按下

參考程式碼:

#include <stdio.h>
#include <windows.h>

int main()
{
    while (1)
    {
        short sValue = GetKeyState(VK_CAPITAL);
        if (sValue & 0x1)//該值低位位1,則表示CapsLock按下
            printf("Caps Lock key is on\n");
        else
            printf
("Caps Lock key is off\n"); if (GetKeyState(VK_CONTROL) & 0x8000)//ctrl鍵的判斷方法 printf("Ctrl key is on\n"); else printf("Left Ctrl key is off\n"); if (GetKeyState(VK_SHIFT) & 0x8000)//shift鍵的判斷方法 printf("Shift key is on\n"); else printf
("Shift key is off\n"); if (GetKeyState(VK_MENU) & 0x8000)//alt鍵的判斷方法 printf("Alt key is on\n"); else printf("Alt key is off\n"); printf("\n"); Sleep(1000); } return 0; }