未知类型INPUT - windows.h

时间:2018-03-27 10:07:46

标签: c windows input

我最近一直在尝试使用windows.h库,编译器无法找到我使用的某些类型和函数。

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

void moveUp(int with) {
    POINT pos;
    if (!GetCursorPos(&pos)) {
        puts("Unable to get cursor position\n");
        exit(-1);
    }
    if (!SetCursorPos(pos.x, pos.y - with)) {
        puts("Unable to move cursor\n");
        exit(-1);
    }
    puts("Success");
}

int getScreenHeight() {
    return GetSystemMetrics(SM_CYSCREEN);
}

void click(int x, int y) {
    INPUT myInput;
    myInput.type = INPUT_MOUSE;
    MOUSEINPUT mouseStruct;
    mouseStruct.dx = x;
    mouseStruct.dy = y;
    mouseStruct.dwFlags = MOUSEEVENTF_XDOWN;
    mouseStruct.mouseData = XBUTTON1;
    mouseStruct.time = 0;
    mouseStruct.dwExtraInfo = NULL;
    myInput.mi = mouseStruct;
    SendInput(1,&myInput,sizeof(INPUT));
}

void startMenu() {
    int height = getScreenHeight();
    if(!SetCursorPos(20,height + 20)){
        puts("Unable to move cursor\n");
        exit(-1);
    }
    click();
}

int main(){
   moveUp(200);
   startMenu();
   return 0;
 }

我在标题中得到了上面的错误,尽管如你所见,包含了windows.h。我怎么能解决这个问题?或者是否需要使用不同的标题?

1 个答案:

答案 0 :(得分:1)

仅从Windows&gt; = 2000开始支持

INPUT

因此,您需要define WINVER and/or _WIN32_WINNT才能使用它。另请阅读Using the Windows Headers