先上代码:
#include <iostream>
#include <Windows.h>
int main()
{
SHORT my_CAPITAL= GetKeyState(VK_CAPITAL);
SHORT my_NUMLOCK= GetKeyState(VK_NUMLOCK);
}
大写锁定返回1,未锁定返回0,如果在函数执行时,还在按着,那就是-127,如下图:
官网用法:
Virtual-Key Codes (Winuser.h) - Win32 apps | Microsoft Learn
函数定义:
SHORT GetKeyState(
[in] int nVirtKey
);
参数:
PaParameters
[in] nVirtKey
Type: int
A virtual key. If the desired virtual key is a letter or digit (A through Z, a through z, or 0 through 9), nVirtKey must be set to the ASCII value of that character. For other keys, it must be a virtual-key code.
If a non-English keyboard layout is used, virtual keys with values in the range ASCII A through Z and 0 through 9 are used to specify most of the character keys. For example, for the German keyboard layout, the virtual key of value ASCII O (0x4F) refers to the "o" key, whereas VK_OEM_1 refers to the "o with umlaut" key.
是一个ASCII 值,具体的对应定义为:
GetKeyState function (winuser.h) - Win32 apps | Microsoft Learn
防止链接失效,以下是内容:
Constant | Value | Description |
---|---|---|
VK_LBUTTON |
0x01 | Left mouse button |
VK_RBUTTON |
0x02 | Right mouse button |
VK_CANCEL |
0x03 | Control-break processing |
VK_MBUTTON |
0x04 | Middle mouse button (three-button mouse) |
VK_XBUTTON1 |
0x05 | X1 mouse button |
VK_XBUTTON2 |
0x06 | X2 mouse button |
- |
0x07 | Undefined |
VK_BACK |
0x08 | BACKSPACE key |
VK_TAB |
0x09 | TAB key |
- |
0x0A-0B | Reserved |
VK_CLEAR |
0x0C | CLEAR key |
VK_RETURN </ |