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. Disable control keyboard button
Forum Updated to NodeBB v4.3 + New Features

Disable control keyboard button

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 1.7k Views 3 Watching
  • 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.
  • I Offline
    I Offline
    ivanicy
    wrote on 27 Mar 2017, 10:39 last edited by
    #1

    Hello everyone.

    I have a little question about to disable the control button in keyboard.

    I have a

    *keyPressEvent(QKeyEvent event)

    function and I want to disable de control button. I tried with the

    event->ignore()

    sentence but it doesn't works.

    How I can do this?

    Thank you very much!

    A D 2 Replies Last reply 28 Mar 2017, 03:43
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Mar 2017, 23:03 last edited by
      #2

      Hi,

      IIRC, CTRL is a modifier.

      What exactly do you want to achieve ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I ivanicy
        27 Mar 2017, 10:39

        Hello everyone.

        I have a little question about to disable the control button in keyboard.

        I have a

        *keyPressEvent(QKeyEvent event)

        function and I want to disable de control button. I tried with the

        event->ignore()

        sentence but it doesn't works.

        How I can do this?

        Thank you very much!

        A Offline
        A Offline
        ambershark
        wrote on 28 Mar 2017, 03:43 last edited by
        #3

        @ivanicy Are you saying you want to stop the control button from being used anywhere in the OS? Or just in your application?

        You won't be able to disable it for the OS using Qt, you will need to go native for that.

        It will be mildly difficult in your application as well. What is your reason for wanting to disable control? It is a very used modifier key in all OSes and really should not be disabled. I can guarantee I wouldn't use your app if it disabled my ctrl key. ;)

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        0
        • I ivanicy
          27 Mar 2017, 10:39

          Hello everyone.

          I have a little question about to disable the control button in keyboard.

          I have a

          *keyPressEvent(QKeyEvent event)

          function and I want to disable de control button. I tried with the

          event->ignore()

          sentence but it doesn't works.

          How I can do this?

          Thank you very much!

          D Offline
          D Offline
          Devopia53
          wrote on 28 Mar 2017, 06:42 last edited by
          #4

          @ivanicy

          Use nativeEventFilter() if you only need to use it in your application.
          The following example is intended for use with Windows. It can be used similarly on other operating systems.

          [...]
          #include <QAbstractNativeEventFilter>
          #include <QDebug>
          #include <windows.h>
          
          class MyWindowsEventFilter : public QAbstractNativeEventFilter
          {
          public:
              virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *) Q_DECL_OVERRIDE
              {
                  if (eventType == "windows_generic_MSG") {
                      MSG* ev = static_cast<MSG *>(message);
                      if (ev->message == WM_KEYDOWN && GetAsyncKeyState(VK_CONTROL)) {
                          qDebug() << "Captured CONTROL+" << ev->wParam;
                          return true;
                      }
                  }
                  return false;
              }
          };
          [...]
          
          // in main.cpp
          [...]
          QApplication a(argc, argv);
          a.installNativeEventFilter(new MyWindowsEventFilter);
          [...]
          

          If you want to capture only the CONTROL key, modify it as follows.

          [...]
          if (ev->message == WM_KEYDOWN && GetAsyncKeyState(VK_CONTROL)) {
              if (ev->wParam == VK_CONTROL) {
                  qDebug() << "Captured CONTROL key";
                  return true;
              }
          }
          [...]
          
          1 Reply Last reply
          1

          1/4

          27 Mar 2017, 10:39

          • Login

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