[SOLVED] Error SendInput() to emulate keyboard events! Has anyone done this in Qt windows?
-
wrote on 30 Apr 2012, 19:00 last edited by
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!
-
wrote on 1 May 2012, 04:50 last edited by
You can give a try to
@
LIBS += -luser32
@ -
wrote on 3 May 2012, 20:20 last edited by
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!
-
You can give a try to
@
LIBS += -luser32
@wrote on 11 May 2020, 07:46 last edited by@dbzhang800 said in [SOLVED] Error SendInput() to emulate keyboard events! Has anyone done this in Qt windows?:
You can give a try to
@
LIBS += -luser32
@not working for me.