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. How to get QChar from KeyPress using WinAPI?
Forum Updated to NodeBB v4.3 + New Features

How to get QChar from KeyPress using WinAPI?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.8k 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.
  • Z Offline
    Z Offline
    zither
    wrote on 3 Oct 2011, 09:24 last edited by
    #1

    Dear all,
    I try to use like that. But it returns same value for both 'a' & 'A'.

    How can I get differentiate them by using WinAPI?
    That's code is OK with Visual Studio C++. Is this a bug in Qt?
    Thanks

    @LRESULT CALLBACK WinHook::keyboardProcedure(int nCode, WPARAM wParam, LPARAM lParam)
    {
    if (nCode == HC_ACTION){
    if (wParam == WM_KEYDOWN){
    KBDLLHOOKSTRUCT p = (KBDLLHOOKSTRUCT) lParam;
    BYTE *keyboardState;
    keyboardState = new BYTE[256];
    if (GetKeyboardState(keyboardState)){
    WORD wChar;
    int ra = ToAscii((UINT)p->vkCode,(UINT)p->scanCode,keyboardState,&wChar,0);
    if (ra>0){
    qDebug()<<"wChar is "<<wChar; //return same for both 'a' & 'A'
    }
    }
    }
    @

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 3 Oct 2011, 09:39 last edited by
      #2

      It looks like one of your API calls does not respect the SHIFT flag. You might check if VK_SHIFT resp. VK_LSHIFT or VK_RSHIFT is set in keyboardState.

      Is there any reason you use platform-specific code in the first place?

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zither
        wrote on 3 Oct 2011, 10:17 last edited by
        #3

        I think,
        @GetKeyboardState(keyboardState);@
        already includes VK_SHIFT state. If so, How can I set VK_SHIFT in keyboardState?

        For reason,
        I'm writing windows hook keyboard Input program with Qt. So, I have no choice to use WinAPI.

        Thanks

        1 Reply Last reply
        0

        3/3

        3 Oct 2011, 10:17

        • Login

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