[SOLVED] Error SendInput() to emulate keyboard events! Has anyone done this in Qt windows?



  • So what I am trying to do right now is get a virtual keyboard going for windows in Qt. I want to use the Qt GUI to make the keyboard and send system events in windows. From what I read, I need to use the SendInput() function which sends system messages to the Win OS to emulate a keyboard press or mouse press. I cant get it to work in Qt! (compiler msvc2008)

    Heres what I include in my file:
    @
    #ifdef Q_WS_WIN
    #define WINVER 0x0500
    #include "Windows.h"
    #include "WinUser.h"
    #endif
    @

    Here is the code snipet I am trying to run.
    @
    #ifdef Q_WS_WIN
    INPUT key;
    key.type = INPUT_KEYBOARD;
    key.ki.wScan = 0; // hardware scan code for key
    key.ki.time = 0;
    key.ki.dwExtraInfo = 0;
    key.ki.wVk = 0x41; // virtual-key code for the "a" key
    key.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &key, sizeof(INPUT));
    key.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
    SendInput(1, &key, sizeof(INPUT));
    return;
    #endif
    @

    I guess my question is, does Qt allow linking directly to the winapi? Because from what I have read online it should work if I have the includes correctly....

    This is the linking error I am getting:
    keyboard.obj:-1: error: LNK2019: unresolved external symbol __imp__SendInput@12 referenced in function "private: void __thiscall Keyboard::sendKeyToSystem(class QString,class QString)" (?sendKeyToSystem@Keyboard@@AAEXVQString@@0@Z)

    Which makes me think that I am not linking to the winapi libraries correctly...has anyone tried using system events for emulating a keyboard? If so, how did you get it to work?

    Thanks!



  • You can give a try to

    @
    LIBS += -luser32
    @



  • This did indeed do the trick. For some reason I thought all of the windows libraries in the system32 or wow64 folder were already linked since windows comes standard with the environment variables. Thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.