Results 1 to 4 of 4

Thread: Detecting keyboard input from any window

  1. #1
    Join Date
    Oct 2019
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Detecting keyboard input from any window

    Is there a way I can monitor keyboard input if the Qt window is not active? In addition to regular alphanumeric keys, I want to passively monitor function keys and control characters.

    I prefer Python, but I'll do it in C++ if I need to. I used pynput to capture keys in PyQt, but it has issues identifying some control keys (like ctrl-. or ctrl-,) which I need.

    I know Qt has built in capturing for its active windows but what about across all windows (without interfering with the intended action of those keys)?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,481
    Thanks
    252
    Thanked 711 Times in 701 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Detecting keyboard input from any window

    If a window does not have the input focus then I don't think it will receive any keyboard events, and I am not sure how a window can have input focus without being active. In any case if you want to capture events from all windows, install an event filter on your application instance. In your filter, be sure to return the correct value or pass the event along to the base class.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Oct 2019
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Detecting keyboard input from any window

    Thank you for the response. It looks like pynput can monitor keys even when it doesn't have focus. There are some buried values in its callbacks (something called vk) that help identify some keys, but I had to back it out to map from vk # to actual key.

    JFYI

    Thanks!

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,481
    Thanks
    252
    Thanked 711 Times in 701 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Detecting keyboard input from any window

    Then pynput is probably monitoring the keyboard at a much lower level than Qt. By the time keystrokes get to the Qt GUI level, they have already been filtered through the window system.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Detecting When Keyboard Interacted With
    By brixel in forum Newbie
    Replies: 1
    Last Post: 23rd May 2016, 13:59
  2. Command for Reading Input from the keyboard
    By parulkalra14 in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2014, 09:11
  3. How can I set the keyboard input mode?
    By Santiago in forum Newbie
    Replies: 3
    Last Post: 15th November 2011, 13:21
  4. keyboard - detecting key pressed
    By Tomasz in forum Newbie
    Replies: 9
    Last Post: 19th April 2011, 13:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.