我正在尝试使用SendInput()
功能。我写了这段代码:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winuser.h>
#define WIN32_LEAN_AND_MEAN
//...
KEYBDINPUT kbi;
kbi.wVk = 0x31;
kbi.wScan = 0;
kbi.dwFlags = 0;
kbi.time = 0;
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki = kbi;
SendInput(1, &input, sizeof input);
编译:
gcc -Wall -o window.exe win32.c -lWs2_32
我得到:
win32.c: In function ‘main’:
win32.c:13:2: error: ‘KEYBDINPUT’ undeclared (first use in this function)
win32.c:13:2: note: each undeclared identifier is reported only once for each function it appears in
win32.c:13:13: error: expected ‘;’ before ‘kbi’
win32.c:14:2: error: ‘kbi’ undeclared (first use in this function)
win32.c:20:2: error: ‘INPUT’ undeclared (first use in this function)
win32.c:20:8: error: expected ‘;’ before ‘input’
win32.c:21:2: error: ‘input’ undeclared (first use in this function)
win32.c:21:15: error: ‘INPUT_KEYBOARD’ undeclared (first use in this function)
我不知道如何解决这个问题。根据文档,它在Winuser.h
标题中声明。但对我不起作用。