How to hold "shift" + click + drag?

Asked by Michael Bauman

Hi,

I am trying to use Sikuli within an application called Device Anywhere. Within this program, to scroll within a window one needs to hold "shift" + click + drag the mouse. (This emulates a swipe on a phone/tablet.) I was wondering if there is a way to to this simply. I am not too familiar with scripting languages, so I am attempting to do this within the GUI.

Thank you for your help!

Question information

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

keyDown(Key.SHIFT)
dragDrop()
keyUp()

Revision history for this message
Michael Bauman (michael-bauman) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
UNCCheezy (shawny2005) said :
#3

I'm trying this on mac 1.0.1 and it's not working correctly. Is there any gotchas?

Revision history for this message
UNCCheezy (shawny2005) said :
#4

keyDown(Key.SHIFT)
click("1387481377712.png")
click("1387481334149.png")
keyUp()

with the expected output to select all the images inside the region (think images in a finder window)

Revision history for this message
RaiMan (raimund-hocke) said :
#5

tested with Mac 10.9 and Sikuli 1.0.1:

-- this works in Finder: (selects a series of files)
switchApp("Finder")
w = App.focusedWindow()
w.highlight(1)
hover(w.aboveAt(85).right(70))
click(atMouse())
click(atMouse().below(145), KeyModifier.SHIFT)

-- and this works on Finder too:
switchApp("Finder")
w = App.focusedWindow()
w.highlight(1)
hover(w.aboveAt(85).right(70))
click(atMouse())
keyDown(Key.SHIFT)
click(atMouse().below(145))
keyUp()

-- and this works on Safari: (selects a paragraph of text)
switchApp("Safari")
w = App.focusedWindow()
w.highlight(1)
click(find("1387529851452.png").leftAt(-10))
keyDown(Key.SHIFT)
click(w.find("1387529982182.png").aboveAt(-10))
keyUp()
click(w.find("1387529982182.png").aboveAt(-10), KeyModifier.SHIFT)

-- and this works on Safari too
switchApp("Safari")
w = App.focusedWindow()
w.highlight(1)
click(w.find("1387529851452.png").leftAt(-10))
click(w.find("1387529982182.png").aboveAt(-10), KeyModifier.SHIFT)

Revision history for this message
UNCCheezy (shawny2005) said :
#6

I will try this out. Thanks.

Revision history for this message
UNCCheezy (shawny2005) said :
#7

Hmm. It does seem to work in my environment. But, I am unable to get it to work in my application (flash) Can you think of anything why it might not be working?

Revision history for this message
UNCCheezy (shawny2005) said :
#8

It's a Google Chrome/mac issue. Works in my app on Safari.

Also works in win7/google chrome.

Not sure why its an issue on only mac/chrome.

Revision history for this message
RaiMan (raimund-hocke) said :
#9

could you paste the exact snippet you are using?

Revision history for this message
RaiMan (raimund-hocke) said :
#10

... and tell exactly, what the difference is?

Revision history for this message
UNCCheezy (shawny2005) said :
#11

This is all I'm doing. In the Google Chrome Version, multiple things aren't selected. In Safari, they are selected correctly. Think selecting text. My App is a little different, but should work the same way.

Did you try google chrome on mac?

click("1388513124044.png")
click("1388513458216.png",KeyModifier.KEY_SHIFT)

Revision history for this message
UNCCheezy (shawny2005) said :
#12

Also, in my App, if I manually click an image, and then shift-click another, it selects all of them inbetween. The simple sikuli script doesn't work correctly, and just clicks the second one. Is there a way to change the time it holds down the shift key before or after the click similar to dragSetting??

Revision history for this message
RaiMan (raimund-hocke) said :
#13

this lets you control everything:

keyDown(Key.SHIFT)
wait(0.1)
mouseDown(Button.LEFT)
wait(0.1)
mouseUp()
wait(0.1)
keyUp()

Revision history for this message
UNCCheezy (shawny2005) said :
#14

That works correctly. But it's not working in my App still. Not sure why...

Revision history for this message
RaiMan (raimund-hocke) said :
#15

Any chance to test your app here?

Revision history for this message
UNCCheezy (shawny2005) said :
#16

I can't post it here, but I might be able to screenshare with you sometime if that works. I'll have to talk to the boss.

Revision history for this message
Zach (zachary-lockard) said :
#17

I am having a similar problem. On a web app using flash, I'm attempting to drag and drop an object from a menu onto another surface in the app. This of course works fine manually, but the dragDrop() always fails. I'm using Chrome, but on Windows 7 not mac. I have searched but there is no alternative method within the app for doing what I want (which I feel is poor design, but is neither here nor there). I've tried a number of dragDrop() replacements as suggested above, but none of these are working. My current code is:
folders.hover(targetFile.png)
mouseDown(Button.LEFT)
wait(1)
center.hover(dashboard.png)
mouseUp()

I know it's an issue on the clicking side, because when manually dragging, there is an icon, but when the script runs, there is no icon, which means the app does not register the drag. Any help would be appreciated.

Thanks,
Zach

Revision history for this message
RaiMan (raimund-hocke) said :
#18

@Zach
When asking questions deep down as comment in other questions you should subscribe to the question to get notified!
This time I did it for you.

might be, that a wait after the hover is needed:

folders.hover(targetFile.png)
wait(0.5)
mouseDown(Button.LEFT)
wait(0.5))
center.hover(dashboard.png)
wait(0.5)
mouseUp()

my experience: wait(0.5) is usually sufficient with mouse ops