简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM