user2491404
user2491404

Reputation: 11

keybd_event on Qt won't work

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?

Upvotes: 1

Views: 578

Answers (1)

vahancho
vahancho

Reputation: 21220

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.

Upvotes: 1

Related Questions