Click here to Skip to main content
12,944,475 members (51,346 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I currently repairing some bugs on the Directory System.
This system has a Webview panel and also a virtual keyboard.
This system was developed by using QML, Javascript and 1% of C++.
The virtual keyboard has error in the codes. I entered lower case 'a',in the website textbox it will appear as upper-case'A'. And this happen to all the character from A to Z.

And another problem is when I entered Symbols, there will be weird character appearing in the textbox.

Here below source from Event Panel QML file.
    //------------------------------------------------------
    //                    Keyboard
    //------------------------------------------------------
 
    WebKeyboardPad
    {
        id: keyboard
        x: 0
        y: event_panel.height + keyboard.height;
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked: Globals.onKeyboardClicked(tag);
        onBackspace: Globals.onKeyboardBackspace();
        opacity: 1
 
        Behavior on y
        {
            id: behavior_nb_keyboard_y
            enabled: keyboard.isDragging
            NumberAnimation { duration: 300; }
        }
        Behavior on opacity
        {
            NumberAnimation { duration: 300; }
        }
    }

This source is from a JavaScript file;
function onKeyboardClicked(keyName)
{
    home_main.onKeyboardClicked(keyName);
}
 
function onKeyboardBackspace()
{
    home_main.onKeyboardClicked("backspace");
}

This from Main QML file
//---------------------------------------------------
   // Custom plugins
   //---------------------------------------------------
 
   HardwareInfo
   {
       id: syshardware
   }
 
   function onKeyboardClicked(Keys)
   {
       myKeyboard.simulateKey(Keys);        //Injected in main.cpp
   }
 
   function onKeyboardBackspace(KeyNavigation)
   {
       myKeyboard.simulateKey(KeyNavigation);        //Injected in main.cpp
       //search_box.backspaceKey();
   }


Here the last one is the C++ file

keyboard.cpp

I got change the keyboard.cpp file but when I try which the c++ code change, the result still the same.
#include "keyboard.h"
#include <qevent>
#include <qkeyevent>
#include <qapplication>
 
Keyboard::Keyboard(QObject *parent) : QObject(parent)
{
    theWidget = NULL;
}
 
void Keyboard::setWidget(QWidget* theWidget)
{
    this->theWidget = theWidget;
}
 
void Keyboard::simulateKey(QString keyName)
{
    Qt::Key keycode = getKeyCodeFromName(keyName);
    if (keycode == Qt::Key_unknown || this->theWidget == NULL)
        return;
 
    //A-Z
    if (keyName.length() == 1 && keyName[0].unicode() >= 'A' && keyName[0].unicode() <= 'Z')
    {
        QKeyEvent keyPressEvent(QEvent::KeyPress, keycode, Qt::ShiftModifier);
        QApplication::sendEvent(this->theWidget, &keyPressEvent);
 
        QKeyEvent keyReleaseEvent(QEvent::KeyRelease, keycode, Qt::ShiftModifier);
        QApplication::sendEvent(this->theWidget, &keyReleaseEvent);
    }
    else
    {
        QKeyEvent keyPressEvent(QEvent::KeyPress, keycode, Qt::NoModifier);
        QApplication::sendEvent(this->theWidget, &keyPressEvent);
 
        QKeyEvent keyReleaseEvent(QEvent::KeyRelease, keycode, Qt::NoModifier);
        QApplication::sendEvent(this->theWidget, &keyReleaseEvent);
    }
 
    qDebug("Simulating key: %s", qPrintable(keyName));
}
 
Qt::Key Keyboard::getKeyCodeFromName(QString keyname)
{
    keyname = keyname.toLower();
    if (keyname.length() < 1)
        return Qt::Key_unknown;
 
    if (keyname == "left")              return Qt::Key_Left;
    else if (keyname == "right")        return Qt::Key_Right;
    else if (keyname == "up")           return Qt::Key_Up;
    else if (keyname == "down")         return Qt::Key_Down;
    else if (keyname == "center")       return Qt::Key_Enter;
    else if (keyname == "enter")        return Qt::Key_Enter;
    else if (keyname == "tab")          return Qt::Key_Tab;
    else if (keyname == "\n")           return Qt::Key_Enter;
    else if (keyname == "cpanel")       return Qt::Key_PageUp;
    else if (keyname == "widget")       return Qt::Key_PageDown;
    else if (keyname == "pgup")         return Qt::Key_PageUp;
    else if (keyname == "pgdown")       return Qt::Key_PageDown;
    else if (keyname == "pageup")       return Qt::Key_PageUp;
    else if (keyname == "pagedown")     return Qt::Key_PageDown;
 
    else if (keyname == "esc")          return Qt::Key_Escape;
    else if (keyname == "del")          return Qt::Key_Delete;
    else if (keyname == "delete")       return Qt::Key_Delete;
    else if (keyname == "backspace")    return Qt::Key_Backspace;
    else if (keyname == "space")        return Qt::Key_Space;
    else if (keyname == " ")            return Qt::Key_Space;
    else if (keyname == "+")            return Qt::Key_Plus;
    else if (keyname == "-")            return Qt::Key_Minus;
    else if (keyname == "*")            return Qt::Key_Asterisk;
    else if (keyname == "/")            return Qt::Key_Slash;
    else if (keyname == "\\")           return Qt::Key_Backslash;
    else if (keyname == ".")            return Qt::Key_Period;
    else if (keyname == ",")            return Qt::Key_Comma;
    else if (keyname == "?")            return Qt::Key_Question;
    else if (keyname == "<")            return Qt::Key_Less;
    else if (keyname == ">")            return Qt::Key_Greater;
    else if (keyname == "=")            return Qt::Key_Equal;
    else if (keyname == "@")            return Qt::Key_At;
    else if (keyname == "!")            return Qt::Key_Exclam;
    else if (keyname == "%")            return Qt::Key_Percent;
    else if (keyname == "$")            return Qt::Key_Dollar;
    else if (keyname == ":")            return Qt::Key_Colon;
    else if (keyname == ";")            return Qt::Key_Semicolon;
    else if (keyname == "(")            return Qt::Key_BracketLeft;
    else if (keyname == ")")            return Qt::Key_BracketRight;
    else if (keyname == "{")            return Qt::Key_BraceLeft;
    else if (keyname =&&&&= "}")            return Qt::Key_BraceRight;
    else if (keyname == "\"")           return Qt::Key_QuoteDbl;
    else if (keyname == "volup")        return Qt::Key_VolumeUp;
    else if (keyname == "voldown")      return Qt::Key_VolumeDown;
    else if (keyname == "mute")         return Qt::Key_VolumeMute;
    else if (keyname == "search")       return Qt::Key_Search;
    else if (keyname == "menu")         return Qt::Key_Menu;
 
    else if (keyname.length() >= 2)
    {
        if (keyname.startsWith('f'))
        {
            bool convertOK = false;
            keyname = keyname.right(keyname.length()-1);
            int findex = keyname.toInt(&convertOK);
            if (convertOK)
                return (Qt::Key)(Qt::Key_F1 + (findex-1));
        }
    }
    else
    {
        //a-z
        if (keyname[0].unicode() >= 'a' && keyname[0].unicode() <= 'z')
            return (Qt::Key)(Qt::Key_A + keyname[0].unicode() - 'a');
 
        //A-Z
        if (keyname[0].unicode() >= 'A' && keyname[0].unicode() <= 'Z')
            return (Qt::Key)(Qt::Key_A + keyname[0].unicode() - 'A');
 
        if (keyname[0].unicode() >= '0' && keyname[0].unicode() <= '9')
            return (Qt::Key)(Qt::Key_0 + keyname[0].unicode() - 'a');
    }
 
    return Qt::Key_unknown;
}

keyboard.h
#ifndef KEYBOARD_H
#define KEYBOARD_H
 
#include <QObject>
#include <QWidget>
 
class Keyboard : public QObject
{
    Q_OBJECT
 
public:
 
    Keyboard(QObject *parent = NULL);
 
    void setWidget(QWidget*);
 
    Q_INVOKABLE void simulateKey(QString keyName);
 
private:
 
    QWidget* theWidget;
 
    Qt::Key getKeyCodeFromName(QString keyname);
 
};
 
#endif // KEYBOARD_H

I have change the cpp file but it still does not work.
Hopefully someone can help me to solve this problem.
Thank you
Posted 11-Dec-12 22:19pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,651
CHill60 3,055
Maciej Los 2,423
Jochen Arndt 1,910
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100