PDA

View Full Version : Help With Media Key Events



painja
8th July 2010, 20:18
Hello All,

I am having a problem with qt properly recognizing when a media key (i.e. play) is pressed in Ubuntu 10.04 (Lucid Lynx).

My program re-implements keyPressEvent(QKeyEvent *e) which works great for all normal keys. It has a GUI that shows the e->key() code and the e->text() in 2 separate labels which is done inside the keyPressEvent(). There's a switch that checks for Qt::Key_F1,Qt::Key_F2,Qt::Key_F3, and Qt::Key_MediaPlay (for starters, will implement other media keys: stop, volume up, volume down, etc., once this is working). This switch exists in another function which receives the key then returns a string determining if a "special key" has been pressed. As mentioned all typical ascii keys work great showing a code/proper text. However the media keys do nothing

The documentation says to use e->accept() to capture media key events, however this does not help. I have also used xev command to see what each keyboard strike represents to the OS. Interestingly enough the media keys only show a "reasonable" response once outputting some number in the first "cell" of a "table" followed by 0's in the other columns. After the first key press they just show 1 followed by 0's throughout that table.

I understand that the volumeControl within the media player class can monitor when a media key is pressed however I tried to implement an event filter in there (with my keyEvent() commented out) and it did nothing at all (not even normal keys). I am using a QMainWindow to do this, would this really cause a problem, I noticed a lot of stuff said QWidget in the volume control example? Although I think this approach may be off-course.

Further, I am not sure if the Operating system is "stealing" the events from my program because the volume up/down and mute buttons execute correctly, however they do not register within my program. I even went into the keyboard shortcuts and changed the "play" event to - on the num-pad and it actually worked. My program gave me a number equiv to Qt::key_MediaPlay.

I'm really stumped on this and In my opinion this should definitely be possible, I mean if you made a media player you would have to connect the play key to some event within your program, correct? Unless your supposed to use those keyshortcut classes for that?

Additionally this is an HP Pavilion laptop, Pentium 4 with 1g RAM.

I am not an expert in Qt however i am very c++ savvy. I would appreciate any help you guys can offer on this, thanks! And sorry for the long post, but imo, the more info the better =D.