1

I'm trying to create some sort of a "virtual controler" on Qt, by sending "keyboard presses" from my apliccation to outside of it (to the system). I tried to use keybd_event, but I'm having problems. Even this simple code won't work:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <windows.h>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    keybd_event(Qt::Key_Right, 0, 0, 0);
    keybd_event(Qt::Key_Right, 0, KEYEVENTF_KEYUP, 0);
}

I get this error message:

mainwindow.obj:-1: error: LNK2019: unresolved external symbol _imp_keybd_event@16 referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AAEXXZ)

Can please someone explain why is wrong with the code?

László Papp
  • 51,870
  • 39
  • 111
  • 135
user2491404
  • 11
  • 1
  • 2

1 Answers1

1

According to this document keybd_event() function defined in User32.dll library. I think you need to verify whether your application is linked against User32.lib.

vahancho
  • 20,808
  • 3
  • 47
  • 55