Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved I need to get the status of Caps-lock on or off in QT framework using c++

    C++ Gurus
    3
    7
    4750
    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.
    • M
      MikeXing last edited by

      Hi All,

      I need to get the status of 'caps-lock' key is on or off in QT framework.

      Suppose if the caps-lock key is on in the keyboard before running any application. I want to read the status of caps-lock key from the keyword using QT framework.

      It would be great if someone helps me in this query.

      Thanks & Regards,

      Mike

      J.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @MikeXing last edited by

        @MikeXing
        you'll most likly need an OS-specific libary.

        In Windows, for example, you could go with

        "WinUser.h" include and use GetKeyState with the VK_CAPITAL key code

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply Reply Quote 1
        • M
          MikeXing last edited by

          Thank you for your reply....
          But i want to do it in linux using QT framework.

          Regards,
          Mike

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @MikeXing last edited by

            @MikeXing
            If @J-Hilk is right, and you can't just use Qt to determine this, have a look at http://www.qtcentre.org/threads/30180-how-to-determine-if-CapsLock-is-on-crossplatform or https://stackoverflow.com/questions/9830905/qt-4-7-4-is-there-a-way-to-find-out-the-status-of-caps-lock

            1 Reply Last reply Reply Quote 2
            • M
              MikeXing last edited by

              Another way is i can make forcefully set the caps-lock key to off how do i do it?

              Even though if the caps-lock key is on in the beginning of application, if i could make it forcefully to off my problem will be solved.
              So how do i forcefully make caps-lock key off?

              Regards,
              Mike

              J.Hilk 1 Reply Last reply Reply Quote 0
              • J.Hilk
                J.Hilk Moderators @MikeXing last edited by

                @MikeXing
                Technically still with os specific functions.

                but in this special case you could also use an eventfilter and retranslate alle uppercase Keys into a lower case one.

                e.g: (untested)

                bool eventFilter(QObject* obj, QEvent* event)
                    {
                        if (event->type()==QEvent::KeyPress) {
                            QKeyEvent* key = static_cast<QKeyEvent*>(event);
                             Qt::KeyboardModifiers modifieres = key->modifiers();
                            modifieres.setFlag(Qt::ShiftModifier, false);
                            key->setModifiers(modifieres);
                            return QObject::eventFilter(obj,key);
                        } else {
                            return QObject::eventFilter(obj, event);
                        }
                        return false;
                    }
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

                Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply Reply Quote 0
                • M
                  MikeXing last edited by MikeXing

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post