akisiel
November 28, 2017, 4:32pm
#1
Hi!
I am trying to reproduce fallowing behavoiur using Robot.js class:
press SHIFT key
MouseDown on an element
MouseMove to some other location
MouseUp
As far my code is not working, it behaves like shift it not held. Can anyone know how I can simulate shift down with robot.js?
const dragdrop = { sourceDiagram: this.canvasDiagram, targetDiagram: this.canvasDiagram };
const node = this.canvasDiagram.findNodesByExample({name: res.data.name}).first();
const loc = node.actualBounds.center;
this.robotTest.keyDown(16); //tried also this.robotTest.keyDown(16, 0, {shift:true});
this.robotTest.mouseDown(loc.x, loc.y, this.canvasDiagram.toolManager.dragSelectingTool.delay + 50, dragdrop); this.robotTest.mouseMove(res.data.x, res.data.x, this.canvasDiagram.toolManager.dragSelectingTool.delay + 200, dragdrop);
this.robotTest.mouseUp(res.data.x, res.data.y, this.canvasDiagram.toolManager.dragSelectingTool.delay + 200, dragdrop);
Thanks!
walter
November 28, 2017, 4:44pm
#2
You do need to pass the { shift: true }
option explicitly.
How do you know that the code is not working as if InputEvent.shift were true?
akisiel
November 29, 2017, 10:54am
#3
@walter thank you!
In our case we have fallowing steps:
have 2 “snapped” nodes
press shift key
click on one node and move it
It should resulted in unsnapped nodes.
I think the code is not working becuase when I run it, the result is not unsnapped nodes but both nodes snapped and moved (which happens when you will do steps above without step 2).
Is there any chance I could check if shift key is still down during mouse move?
walter
November 29, 2017, 11:16am
#4
You need to pretend to hold down the Shift key for all of the mouse events during the whole operation. That means including shift: true
in the options for every mouse event.
akisiel
November 29, 2017, 11:17am
#5
@walter Thank you a lot. I will try :)
akisiel
November 29, 2017, 11:46am
#6
@walter great it works! thank you :)