Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Read keyboard input that can differ between LEFT Shift and RIGHT shift key

    General and Desktop
    2
    5
    2315
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      wilhelmsen last edited by

      Hi, I am writing an application to test keyboards. I have to read input from both the shift buttons, the one on the right and the one on the left, and also for the right and left windows buttons.

      I haven't written any Qt before, but if anyone could write up some example code on how I can capture these inputs from e.g. a QLineEdit (I want to show what character is being typed, irregardless of which shift-button the user press) I would really appreciate it!

      As a bonus, how can I read e.g. ctrl+shift, win+tab etc?

      1 Reply Last reply Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        There is no direct Qt::Key_* like that. You need to look at the native scan code and work on this.

        i.e check for QKeyEvent::nativeScanCode(). This is platform dependent scan code.

        For other question you can use Qt::ControlModifier.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply Reply Quote 0
        • W
          wilhelmsen last edited by

          Thank you. What I struggled with first and foremost was to actually override the QKeyEvent in my widget.
          Thanks for your reply.

          1 Reply Last reply Reply Quote 0
          • dheerendra
            dheerendra Qt Champions 2022 last edited by

            oh. If you had asked that earlier, I would have provided you the sample source code. Any not too late.

            Are you able override the QKeyEvent ? You can following snippet of code for the same.

            @void Widget::keyPressEvent(QKeyEvent *event){
            if (event->modifiers() & Qt::ShiftModifier & Qt::ControlModifier) {
            qDebug() << "Key board modifier is pressed " << endl;
            }
            }
            @

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply Reply Quote 0
            • W
              wilhelmsen last edited by

              Yes, I got it to work. Figured out the protected keyword in the header file also :) how can I now "un-override" it? Not that I need it, but just out of curiousity

              1 Reply Last reply Reply Quote 0
              • First post
                Last post