Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read keyboard input that can differ between LEFT Shift and RIGHT shift key
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.7k Views
  • 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 Offline
    W Offline
    wilhelmsen
    wrote on 15 Jan 2014, 11:50 last edited by
    #1

    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
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 15 Jan 2014, 12:01 last edited by
      #2

      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
      0
      • W Offline
        W Offline
        wilhelmsen
        wrote on 17 Jan 2014, 09:27 last edited by
        #3

        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
        0
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 18 Jan 2014, 02:20 last edited by
          #4

          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
          0
          • W Offline
            W Offline
            wilhelmsen
            wrote on 18 Jan 2014, 08:40 last edited by
            #5

            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
            0
            • P Pl45m4 referenced this topic on 7 Mar 2024, 15:51

            5/5

            18 Jan 2014, 08:40

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved