Results 1 to 6 of 6

Thread: Simulate left and right clicks?

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Simulate left and right clicks?

    Hello.
    I want to know if it is possible to grab somehow the mouse and detect the right, the left clicks and where in the screen they happened and store these values in an integer table like
    int a [ 1, 123, 456 ]
    for example this will mean that it was a right click (1) and happened at 123,456 (x,y)

    After having stored those values I want to repeat these actions, something like a macro.

    I know how to move the mouse to x,y, what I don't know is how actually to
    1) grab the mouse for left and right clicks
    2) Save the data from the "grabbing" in different variables every time and in the end, after the grabbing ends, how do I loop among them so as to repeat the action depending on the data stored?(actually C++ question, not Qt)


    I don't want code ready to execute, I want a bit of guidance here, but sample code for better understanding is welcome.

    Thx in advance for any answer
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Simulate left and right clicks?

    Do you want to grab the mouse in your own application or in windows outside your application?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Simulate left and right clicks?

    As for 2), you can have a list of your own structures, for example:
    Qt Code:
    1. typedef enum{
    2. CLICK_LEFT = 0,
    3. CLICK_RIGHT = 1
    4. } MyClickType;
    5.  
    6. typedef struct{
    7. ClickType type;
    8. QPoint pos;
    9. } MyMouseClick;
    10.  
    11. typedef QList<MyMouseClick> MyMouseClickList;
    To copy to clipboard, switch view to plain text mode 
    On each grabbed click, push back new structure filled with correct data to the list:
    Qt Code:
    1. // somehow you've grabbed the click
    2. QPoint pos = clickPos;
    3. MyClickType type = CLICK_RIGHT;
    4. //... store it in list
    5. MyMouseClickList clickList;
    6. //...
    7. MyMouseClick c;
    8. c.type = type;
    9. c.pos = clickPos;
    10. clickList.push_back( c );
    To copy to clipboard, switch view to plain text mode 
    Clicks will be in the correct order this way (first grabbed click will be first in list).
    Later you can use for example foreach() macro to loop through the list:
    Qt Code:
    1. foreach( const MyMouseClick& c, clickList ){
    2. doSomething(c);
    3. }
    To copy to clipboard, switch view to plain text mode 
    You can introduce a class instead of POD-like struct, but it's up to your preferences.
    Last edited by stampede; 27th May 2011 at 11:22. Reason: corrected wrong word

  4. #4
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Simulate left and right clicks?

    Probably you want to intercept the mouse events. Several ways to do it, depending ... Probably setEventFilter is the best combo of ease and generality.

    You can also intercept mouse events a the widget level (including the main screen widget) with installEventFilter, or you can subclass the appropriate object and override the various MouseEvents.

  5. #5
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Simulate left and right clicks?

    Thx for the replies, but I'd like to capture the mouse clicks not only IN my application, but between all the open windows, desktop, everywhere
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Simulate left and right clicks?

    This is not trivial, and not portable, and beyond the scope of Qt.
    You will have to google it for the platforms on which you want to implement it.
    I found this for windows, but I didn't test it:
    http://www.codeproject.com/KB/system...?display=Print
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 2
    Last Post: 20th December 2010, 17:51
  2. Replies: 4
    Last Post: 29th August 2010, 18:16
  3. Replies: 3
    Last Post: 12th May 2010, 13:11
  4. Simulate QMenu behavior
    By Remenic in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2009, 19:48
  5. how to Simulate the keyboard press
    By duduqq in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2008, 16:50

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.