【发布时间】:2018-04-24 06:50:28
【问题描述】:
我正在尝试使用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)
我不知道如何解决这个问题。根据documentation,它在Winuser.h 标头中声明。但对我不起作用。
【问题讨论】:
-
您可以检查头文件是否已在某个宏下声明了这些结构,在这种情况下,您必须使用
-D选项通过命令行传递该宏定义或在源代码中显式定义它