簡體   English   中英

Qt上的keybd_event無法正常工作

[英]keybd_event on Qt won't work

我正在嘗試通過從我的應用程序向應用程序外部(系統)發送“鍵盤壓力機”,在Qt上創建某種“虛擬控制器”。 我嘗試使用keybd_event,但是出現問題。 即使這個簡單的代碼也行不通:

#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);
}

我收到此錯誤消息:

mainwindow.obj:-1:錯誤:LNK2019:在函數“私有:void __thiscall MainWindow :: on_pushButton_clicked(void)”中引用的未解析的外部符號_ imp _keybd_event @ 16(?on_pushButton_clicked @ MainWindow @@ AAEXXZ)

請問有人可以解釋為什么代碼錯誤嗎?

根據文檔,在User32.dll庫中定義了keybd_event()函數。 我認為您需要驗證您的應用程序是否針對User32.lib鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM