PDA

View Full Version : Filtering all mouse/keyboard events



maverick_pol
26th November 2008, 14:51
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

aamer4yu
26th November 2008, 17:09
Am not sure what u mean by count events.

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

maverick_pol
26th November 2008, 17:22
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

wysota
26th November 2008, 18:41
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.

maverick_pol
26th November 2008, 19:54
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.

wysota
26th November 2008, 20:16
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.

maverick_pol
26th November 2008, 23:43
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.

wysota
27th November 2008, 00:35
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 :)

maverick_pol
27th November 2008, 00:44
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".

Eldritch
27th November 2008, 17:03
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.