How to send message to Desktop Widget - Mandrake

This is a discussion on How to send message to Desktop Widget - Mandrake ; Hi all, I want to send a KeyDown message to the desktop widget which i got through QApplication::desktop(). Here is the code snippet: // Also tried with - Qt::Key_SysReq QKeyEvent keydownEvent(QEvent::KeyPress, Qt::Key_Print, Qt::AltModifier); QDesktopWidget * desktopWidget = qApp->desktop(); qApp->sendEvent(desktopWidget, &keydownEvent); ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: How to send message to Desktop Widget

  1. How to send message to Desktop Widget

    Hi all,
    I want to send a KeyDown message to the desktop widget which i got
    through QApplication::desktop(). Here is the code snippet:



    // Also tried with - Qt::Key_SysReq

    QKeyEvent keydownEvent(QEvent::KeyPress, Qt::Key_Print,
    Qt::AltModifier);
    QDesktopWidget * desktopWidget = qApp->desktop();

    qApp->sendEvent(desktopWidget, &keydownEvent);

    bool bDownAccepted = keydownEvent.isAccepted();
    QKeyEvent keyupEvent(QEvent::KeyRelease, Qt::Key_Print,
    Qt::AltModifier);
    QApplication::sendEvent(desktopWidget, &keyupEvent);
    bool bUpAccepted = keyupEvent.isAccepted();



    Here my assumption was that this code should send an "Alt +
    PrintScreen" button press to the desktop widget which in effect should
    dump the "active window image" to the ClipBoard. But it is not
    happening in my case.
    There is nothing copied to the ClipBoard and also bDownAccepted ,
    bUpAccepted value is always false which means that DesktopWidget is
    not accepting the event.


    My aim is just to capture the image of active window on the screen
    using QT.

    can anybody tell whats wrong with the above code.
    Any help would be appreciated.

    Thnx in advance.

    Shalabh


  2. Re: How to send message to Desktop Widget

    Ansh wrote:

    > Hi all,
    > I want to send a KeyDown message to the desktop widget which i got
    > through QApplication::desktop(). Here is the code snippet:
    >
    >
    >
    > // Also tried with - Qt::Key_SysReq
    >
    > QKeyEvent keydownEvent(QEvent::KeyPress, Qt::Key_Print,
    > Qt::AltModifier);
    > QDesktopWidget * desktopWidget = qApp->desktop();
    >
    > qApp->sendEvent(desktopWidget, &keydownEvent);
    >
    > bool bDownAccepted = keydownEvent.isAccepted();
    > QKeyEvent keyupEvent(QEvent::KeyRelease, Qt::Key_Print,
    > Qt::AltModifier);
    > QApplication::sendEvent(desktopWidget, &keyupEvent);
    > bool bUpAccepted = keyupEvent.isAccepted();
    >
    >


    Don't know, but *may* be related to below:

    > Here my assumption was that this code should send an "Alt +
    > PrintScreen" button press to the desktop widget which in effect should
    > dump the "active window image" to the ClipBoard. But it is not
    > happening in my case.
    > There is nothing copied to the ClipBoard and also bDownAccepted ,
    > bUpAccepted value is always false which means that DesktopWidget is
    > not accepting the event.


    I would steer clear of ALT+SysRQ as adding one more key generates emergency
    signals to the linux kernel (eg Alt+SysRQ+b reboots hard, no disk sync,
    nothing, unless SysRQ handling is disabled).

    Wondering if that is preventing the keypresses from getting to the
    application or not.

    What about PrintScreen+Shift or Ctrl - does that work?

    Cheers

    Tim

+ Reply to Thread