0

I have created Web-browser using Active-qt in one widget and in the second widget I am having a virtual keyboard created by me. I have to write in the text box of browser(for example google search box) with virtual keyboard. I am using key-board send event method to send the key-press events to browser but it is not writing in the web-browser. When I have created a line edit in the first widget and trying to write via same virtual keyboard then it is writing perfectly but in case of browser it is not writing. So I wanted to access the HTML content of Browser to get the the id of search box of website. So I set the focus to that particular Id. I am helpless please help. Thanks in advance. Technology Stack QT:Active Qt component, Qt 5.7.0, Qt creator IDE with Min Gw and c++.

Edit: code snippet of test case send single button press event to webbrowser attaching designer snap as well as code snippet. enter image description here

    UseKeyBoardDialog::UseKeyBoardDialog(QWidget *parent) : QDialog(parent)

{
    setupUi(this);
    WebBrowser->setControl("8856F961-340A-11D0-A96B-00C04FD705A2");


    QString htmlDoc = WebBrowser->generateDocumentation();
    QString outputFilename = "Results.html";
    QFile outputFile(outputFilename);
    outputFile.open(QIODevice::WriteOnly);
    /* Check it opened OK */
        if(!outputFile.isOpen()){
           qDebug() << "- Error, unable to open" << outputFilename << "for output";
        }
        /* Point a QTextStream object at the file */
        QTextStream outStream(&outputFile);
        /* Write the line to the file */
        outStream << htmlDoc;
        /* Close the file */
        outputFile.close();
    //qDebug()<<"htmlDoc "<<htmlDoc;

}

void UseKeyBoardDialog::navigate(const QString &url)
{
    WebBrowser->dynamicCall("Navigate(const QString&)", url);
}

void UseKeyBoardDialog::on_pushButton_clicked()
{
     // lineEdit->setFocus();
    WebBrowser->setFocus();

           keybd_event( 0,
                        0x1E,
                        KEYEVENTF_SCANCODE| 0,
                        0 );

        // Simulate a key release
           keybd_event( 0,
                        0x1E,
                        KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE,
                        0);



}
  • you have to simulate keyboard events using your virtual keyboard then it will work everywhere otherwise Sent event will only work for Qt widgets. I am not sure it supports for content inside browser or not. which OS you are using ? – SourabhKus Jun 07 '17 at 10:25
  • I am using windows 7 – Vidya Tiwari Jun 07 '17 at 10:34
  • @Sourabh: I am using windows 7 – Vidya Tiwari Jun 07 '17 at 11:08
  • you can access winApi for simulation of KB events, like [here](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx) – SourabhKus Jun 07 '17 at 11:12
  • @Sourabh: I have already tried this simulation and is working for different widgets of qt like line edit but not for the searchbox of google search engine or any websites text box. – Vidya Tiwari Jun 07 '17 at 12:56
  • show me code, because i developed virtual keyboard for Win/Linux 3 to 4 year ago, and that was working for all window and browser too like windows inbuild VK. – SourabhKus Jun 08 '17 at 05:45
  • keybd_event function has been superseded. Use SendInput instead. – SourabhKus Jun 08 '17 at 09:17

1 Answers1

0

To write in web browser use SendInput method to send the artificial keystroke to the browser on buttonclick event and it will work for every browser. Before sending keystroke you should have to maintain your web browser on top everytime on button click. Code snippet to write to webbrowser on virtual key press:

void Widget::on_pushButton_clicked() {
ui->axWidget->setFocus(); //setting focus of webbrowser
ui->pushButton->setFocusPolicy(Qt::NoFocus);//focus policy of virtual key 
//webbrowser on top every time 
ui->axWidget->setWindowFlags(Qt::WindowStaysOnTopHint);

   INPUT ip;
        ip.type = INPUT_KEYBOARD;
        ip.ki.wVk = 0x41;
        ip.ki.wScan = 0;
        ip.ki.dwFlags = 0;
        ip.ki.time = 0;
        ip.ki.dwExtraInfo = 0;
        // Send the keyboard event to the specified window
        SendInput(1, &ip, sizeof(INPUT)); }

this code is a sample code displaying a single virtual key press on web browser.