Use a List as a Source for Mouse Dragging Values

After searching for about an hour without finding something I hope that someone maybe can help me get started or let me know that it might be impossible.

I have an editor application that uses virtual knobs to set values. There is no text field for value entries just the knob to be turned using the mouse until the dedicated position that leads to the related and displayed value.

I am looking for a way to transfer values from another application to kind of "drag values" that set the knob accordingly.

First problem and question is: Can a dedicated value - for example taken from the system clipboard - be used to set the dragging value for the mouse?

If yes let's say the knob has a range from 0-127. But the dragging values are not proportional. That's the second problem.

So from the zero position to the knob value "1" a dragging value of -2 might be necessary and to set the knob to "2" might need -6 to drag. This means I would need a list that contains the input and output values like i.e.…

1 = -2
2 = -6
3 = -9
… and so on. And a way to let KM search through this list to search for and find the input value returning the output to drag the mouse accordingly.

Thanks in advance for some hints.

Could you give a more general overview of what you're trying to do with the knobs and what the editor is for? This will help us imagine how to help, as using a list might not be the best solution.

1 Like

You could search through a list -- but KM has a pre-made data structure called a Dictionary made for just this kind of "return a value associated with a key" operation.

In this particular case use could also use an array of numbers -- -2,-6,-9,... and access it directly by element index -- slightly more difficult to maintain, but probably faster in execution.

So it's doable but, as @noisneil says, there may be a better solution anyway.

1 Like

Thank you both, @noisneil and @Nige_S for taking a look at my topic and your answers.

Apologies that my description obviously wasn't clear enough.

Unfortunately I can't share the target application I am working with because it is an unreleased beta.

But I demonstrated my goal in a small screencast with two other applications. The one at the bottom is my source and for this example I like to convert the value "Level 1" of 117 into a dragging action for the upper app to set the "Amp Level" accordingly. Since I don't know where the current value of the target is I created a dragging action to set it to 0 and then used a value of -172 to drag which results in the knob value of 117. Please just ignore the ".3". As mentioned this is just an example for demonstration purposes.

The Dictionary is pretty cool but it would be a lot of work to create Dictionaries for all the values because I have more different ones and not all knobs are behaving the same. That was the reason for me to think of a list or something similar.

I hope this makes it more clear and thank you again!

There's not much difference between the work involved in setting up a Dictionary and that for a list that's the way you describe it in the OP -- they're both collections of key/value pairs. But a Dictionary is more accessible programmatically.

I still think you can get away with a simple array in this case, since the OP implies you have a complete sequential integer range from 0-127 -- that will map nicely to an array index. The only wrinkle is whether you need a 0 value, in which case you need to include that as the first element of your list and add 1 to the "knob value" when accessing the list:

Zero Value Drag List.kmmacros (3.2 KB)

Image

If you aren't using a 0 value just miss out the + 1 when accessing the array.

Easiest way to create/manage that list is with a text editor that has line numbers displayed. One value on each correspondingly numbered line (remembering to add 1 to the line number if you are including a 0 value on line 1), then search/replace line-endings with , and "Select All", "Copy", and "Paste" into your KM variable.

1 Like

Thanks so much @Nige_S. These are great ideas and as always I learned new things.

Since my source value should be taken from another application I successfully replaced the "Prompt…" with "Set variable "Local_chosenNumber" to %SystemClipboard%".

The only thing I can't imagine now is how to create the mouse drag with the result of i.e. "-14" because during my tests yesterday I wasn't able to use a variable in that "and drag to" field.

Is there a way to do that?

That's because you are using a text Token in a Numeric field. Either use the variables directly:

Local_valueList[Local_chosenNumber + 1]

...or wrap the Token in a CALCULATE() function:

CALCULATE(%Variable%Local_valueList[Local_chosenNumber + 1]%)
1 Like

Wow, thanks a lot. Another lesson learned. That worked.

Much appreciated. :grinning: