Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. [SOLVED] Error SendInput() to emulate keyboard events! Has anyone done this in Qt windows?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved 3rd Party Software
4 Posts 3 Posters 6.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vezprog
    wrote on 30 Apr 2012, 19:00 last edited by
    #1

    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!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on 1 May 2012, 04:50 last edited by
      #2

      You can give a try to

      @
      LIBS += -luser32
      @

      T 1 Reply Last reply 11 May 2020, 07:46
      2
      • V Offline
        V Offline
        vezprog
        wrote on 3 May 2012, 20:20 last edited by
        #3

        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!

        1 Reply Last reply
        0
        • D dbzhang800
          1 May 2012, 04:50

          You can give a try to

          @
          LIBS += -luser32
          @

          T Offline
          T Offline
          Talha Celik
          wrote on 11 May 2020, 07:46 last edited by
          #4

          @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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved