Middle Mouse Click

Asked by Shimizoki

How can I click with the middle mouse button?

Do I need to use:

mouseMove(getLastMatch())
mouseDown(Button.MIDDLE)
mouseUp(Button.MIDDLE)

or is there a middleClick(getLastMatch())?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
RaiMan Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

no middleClick() currently. use your approach.

It is up to you, to post a request bug.

Revision history for this message
Shimizoki (shimizoki) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
obiwan-92 (obiwan-92) said :
#3

Hello,
If you need to do a middle click, copy this in a sikuli file and import it at the beginning of your script.
You can use it with nothing, a region or a screen (including the SCREEN varaible).
For example Screen(2).middleClick("img.png")
Regards.

## Middle Click ##
class Region(Region):
    def middleClick(self, psmrl):
        try:
            psmrl = self.find(psmrl).getTarget()
        except:
            pass
        hover(psmrl)
        mouseDown(Button.MIDDLE)
        mouseUp(Button.MIDDLE)
        print "[log] MIDDLE CLICK on", psmrl
class Screen(Screen):
    def middleClick(self, psmrl):
        Region(self.getBounds()).middleClick(psmrl)
def middleClick(psmrl):
    SCREEN.middleClick(psmrl)
SCREEN = Screen(0)