Results 1 to 10 of 10

Thread: Filtering all mouse/keyboard events

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Filtering all mouse/keyboard events

    Hi guys,

    I have recently concentrated on events, and would like to ask ths question:
    I have an application of which, mainly, only the trayicon is visible; Howcan I count keyboard/mouse events when the app is running?

    Thanks,

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Filtering all mouse/keyboard events

    Am not sure what u mean by count events.

    But have u looked at installing event filters ?? or QWidget::event function ?

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filtering all mouse/keyboard events

    Hi,

    I have read almost all about events from docs/examples/labs/centre, but I need to filter all events in the event loop (main event loop created by qApp->exec()). If I am going to set a filter on the mainwindow, but the mainwindow will be closed for most of the time, and only the trayicon will be active all the time, will I really get all mouse/keyboard events counted ?

    Is there a way to filter all events comming to the main event loop?

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Filtering all mouse/keyboard events

    You can install an event filter on the application object itself - this will give you access to all events passed to all objects in the application. But on the other hand I'm not sure if you will get any events at all if you don't have a window active.

  5. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filtering all mouse/keyboard events

    But on the other hand I'm not sure if you will get any events at all if you don't have a window active.
    Hope you're wrong : )

    I belive that the application will get every event, but not all will be handled/send due to not active window, but no speculation needed, I will test it right away.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Filtering all mouse/keyboard events

    Quote Originally Posted by maverick_pol View Post
    Hope you're wrong : )
    I strongly doubt that. Who would be receiver of those events? The application only gets those events that are directed to it by the desktop manager.

  7. #7
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filtering all mouse/keyboard events

    Unfortunately for me, you seem to be right : (

    It looks like that I should use platform specifis code to count mouse/key events.

    Any idea howto do this? I need to work it out for mac os X, linux, windows.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Filtering all mouse/keyboard events

    For windows you need something that is called a hook, for Unix you need to politely ask X11 to send you all events (don't ask me how) and for Mac... I have no idea

  9. #9
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filtering all mouse/keyboard events

    Thanks for the hints.
    Someone said that mac os x is the hardest os to count events but surely can be done.
    So... I go to hooks/x11 and mac "sth".
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  10. #10
    Join Date
    Aug 2006
    Posts
    44
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filtering all mouse/keyboard events

    Have you investigated QAbstractEventDispatcher::setEventFilter()? Not sure how this works on the Mac, but that, combined w/ the OS-specific event filter on QApplication may be what you need.

    My experience using this is primarily windows-focused up to this point, and I found that I can get my hands on everything, albeit in an OS-specific way.

    Then again, mouse/key data is directed to a specific destination (window), so I guess perhaps the more pertinent question is, whose mouse/key messages are you trying to get?

    As wysota pointed out, if what you're really looking for is capturing all user input on the entire desktop, you're in for a very platform- (and even desktop-) specific task. In Windows, a hook is the usual mechanism, but having some experience with those, all I can say is caveat emptor. You're dealing with an extremely sensitive part of the system there.

Similar Threads

  1. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 15:03
  2. processevents, filtering events
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2006, 22:49

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.