Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Low level keyboard hook on windows ce

Low level keyboard hook on windows ce

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 1 Posters 3.9k Views 1 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.
  • L Offline
    L Offline
    Locutus
    wrote on last edited by
    #1

    Hi all,

    I have tried and looked everywhere however, I cannot seem to find a way to low level keyboard hook under windows ce. All the examples I have found use SetWindowsHookEx which is apparently unsupported under windows ce. The examples for windows ce I have found use loadlibrary to load coredll.dll and call the SetWindowsHookEx function that way.

    As far as I know there is QLibrary which can perform the same function unfortunately I am unable to wrap my head around combining these concepts.

    Does anyone know of a way to low level keyboard hook on windows ce and show me how I can do it? Example code would be fantastic or even an RTFM this old head of mine can understand.

    Thanks for your time.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Locutus
      wrote on last edited by
      #2

      I have been doing some research on this and this is what I have managed to come up with.

      In the header I have put
      @
      #include <QtGui/QMainWindow>
      #include <QLibrary>

      typedef struct tagKBDLLHOOKSTRUCT {
      DWORD vkCode;
      DWORD scanCode;
      DWORD flags;
      DWORD time;
      ULONG_PTR dwExtraInfo;
      } KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT, *LPKBDLLHOOKSTRUCT;

      class testClass : public QMainWindow
      {
      Q_OBJECT
      private:
      friend LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM wparam, LPARAM lparam);
      }@

      in the implementation file I have.

      @
      #include "testClass.h"

      LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM wparam, LPARAM lparam)
      {
      int HC_ACTION = 0;

      typedef int (cNextHookEx)(int, int, WPARAM, LPARAM);
      cNextHookEx CallNextHookEx = (cNextHookEx) QLibrary::resolve("coredll","CallNextHookEx");
      KBDLLHOOKSTRUCT
      kllhs = reinterpret_cast<KBDLLHOOKSTRUCT*>(lparam);
      if (code == HC_ACTION)
      {
      if (wparam == WM_KEYDOWN && (kllhs->vkCode == VK_F3 || kllhs->vkCode == VK_F4) &&
      (GetAsyncKeyState(VK_MENU) < 0 && GetAsyncKeyState(VK_CONTROL) < 0))
      {
      mobiMeter* w = dynamic_cast<mobiMeter*>(qApp->activeWindow());
      if (NULL != w)
      {
      qDebug() << " this should not be blocking!";
      return 1;
      }
      }
      }

      return CallNextHookEx(0, code, wparam, lparam);
      

      }

      testClass::testClass(QWidget *parent, Qt::WFlags flags)
      : QMainWindow(parent, flags)
      {
      int WH_KEYBOARD_LL = 20;
      ui.setupUi(this);
      typedef int (*sWindowHookEx)(int, int, int, int);
      sWindowHookEx SetWindowsHookEx = (sWindowHookEx) QLibrary::resolve("coredll","SetWindowsHookEx");
      SetWindowsHookEx(WH_KEYBOARD_LL,
      (int)LowLevelKeyboardProc,
      NULL,
      0);

      }@

      It compiles fine yet when I try to run it, it crashes. Now I don't know what to do :( Any ideas?

      1 Reply Last reply
      0

      • Login

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