在 Windows 系统中,可以使用 SetWindowsHookEx 函数来设置钩子,来监听键盘事件。需要注意的是,调用该函数需要使用 Windows API。下面是一个简单的例子:
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib")
HHOOK g_hHook = NULL;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
KBD