Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Capturing Joystick button presses
Qt 6.11 is out! See what's new in the release blog

Capturing Joystick button presses

Scheduled Pinned Locked Moved Unsolved Qt for Python
1 Posts 1 Posters 689 Views
  • 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.
  • J Offline
    J Offline
    jcampbellco
    wrote on last edited by
    #1

    Hello all! I'm attempting to create what's effectively a keybinding dialog box (ie: capture a keypress to store for later use).

    My dialog widget - which extends QDialog - has this eventFilter function set up:

    def eventFilter(self, watched: QObject | None, event: QEvent | None) -> bool:
    
        events = [
            QEvent.Type.KeyRelease,
            QEvent.Type.KeyPress,
            QEvent.Type.Wheel,
            QEvent.Type.MouseButtonPress,
            QEvent.Type.MouseButtonRelease,
        ]
    
        if watched is self and event.type() in events:
            print("{0} - Key `{1}` | Button `{2}`".format(
                event.type().name, 
                event.key() if hasattr(event, 'key') and callable(getattr(event, 'key')) else "",
                event.button() if hasattr(event, 'button') and callable(getattr(event, 'button')) else "",
            ))
    
        return super().eventFilter(watched, event)
    

    It's mostly there, I can see keyboard presses, mouse presses, wheel scrolling:

    b786e254-5e0e-4b32-bbaa-25633049ef71-image.png

    But I also would like to be able to capture joystick inputs too, and I'm just not seeing those come through or any event types that look like them.

    I have a "controller" (in this case a button box) that is set up and recognized in Windows:
    a831ded9-73b2-40f3-b4a0-501f312b79fa-image.png

    How can I capture these specific button-press-events emitting from joysticks/controllers?

    I'm sure there is an answer out there I apologize I'm having trouble finding it, most of my searches have yielded results towards replicating a joystick rather than using one as input. Perhaps I'm just trying to use Qt as a hammer for a problem that isn't nail shaped after all lol.

    Happy to add any more details if they will help, thanks y'all for any help in advance!

    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