Mouse click and drag in Davinci Resolve
Hello,
I'm trying to control the UI in Davinci Resolve using mouse click and drag, unfortunately there is no other way to access the specific features that I'm looking to control. In this case I'm setting up a template to edit things like colour temperature, tint etc.
There are a few errors in my script that I have not figured out how to fix, can you help?
There are a few errors:
-
sf.mouse.getPosition().then
Property "then" does not exist on type -
targetPosition Type '{ x: number; y: number; }' has no properties
in common with type 'MouseSetPositionActionArgs'
const appID = 'com.blackmagic-design.DaVinciResolve';
const positionStartX = 394;
const positionStartY = 1023;
// Activate selected application
sf.ui.app(appID).appActivate();
// Get current mouse position and store it for later
sf.mouse.getPosition().then(currentMousePosition => {
// Move mouse to a specific place
const targetPosition = {x: positionStartX, y: positionStartY};
sf.mouse.setPosition(targetPosition);
// Mouse click down
sf.mouse.down();
// Mouse drag a specific amount
const dragAmount = {x: 0, y: 50};
const endPosition = {
x: targetPosition.x + dragAmount.x,
y: targetPosition.y + dragAmount.y
};
sf.mouse.simulateDrag({
endPosition: endPosition
});
// Mouse up at the same end point
sf.mouse.up({
position: endPosition
});
// Move the mouse back to the original position
sf.mouse.setPosition(currentMousePosition);
});
- Kitch Membery @Kitch2023-04-23 20:36:41.513Z
Hi @Andrew_Sherman,
To get the original position of the mouse use this.
const originalMousePosition = sf.mouse.getPosition().position;
To restore the mouse position at the end of the script use this.
sf.mouse.setPosition({ position: originalMousePosition, });
To simulate a drag do something like this.
const originalMousePosition = sf.mouse.getPosition().position; const startPosition = originalMousePosition const endPosition = { x: 1000, y: 1000 } sf.mouse.simulateDrag({ startPosition, endPosition, }); sf.mouse.up(); sf.mouse.setPosition({ position: originalMousePosition, });
- AAndrew Sherman @Andrew_Sherman
Thank you Kitch! I read the forum post on fast drag and it seems somewhat beyond me right now - is there a simple way of converting this to a fast drag instead of the simulation? I want to connect it to a hardware midi control knob so that it drags left by a certain small amount when the wheel turns left, and drags right from the same spot when the wheel is turned right.
Similar to how Nob works.
const appID = 'com.blackmagic-design.DaVinciResolve'; const positionStartX = 394; const positionStartY = 1023; const positionChange = 20; // Activate selected application sf.ui.app(appID).appActivate(); const originalMousePosition = sf.mouse.getPosition().position; /* Horizontal drag Set to minus to subtract */ const startPosition = { x: positionStartX, y: positionStartY } const endPosition = { x: positionStartX-positionChange, y: positionStartY } sf.mouse.simulateDrag({ startPosition, endPosition, }); sf.mouse.up(); sf.mouse.setPosition({ position: originalMousePosition, });