Need help with adding a mouse recall feature to this code | Intech Studio
💬 general Grid

Need help with adding a mouse recall feature to this code

Demetrisag
Demetrisag · · 29 replies

Hey guys, this code is already in the community configs and works really well, (mouse takeover VST controller 1.1) but since I don't really know much about scripting was hoping this someone would help me to modify it so it saves the current mouse location before click and after click release it would go back to the saved location.

if self.axis ~= 3 and self.c_act == false then
mouse_button_send(1, 1)
self.c_act = true
end
if self:encoder_value() > 63 then
mouse_move_send(self.axis, self.step)
else
mouse_move_send(self.axis, self.step * -1)
end
timer_start(self:element_index(), self.time)

Replies (29)

Demetrisag Demetrisag ·

in other words I just want it to come back to its starting place after moving it

Demetrisag Demetrisag ·

Any geniuses out there in the wild?

kkerti kkerti ·

lemme try this, on weekends from Intech we aren't that active 😛

kkerti kkerti ·

If you do not change the mouse position while relying on the encoder making these changes, this can be done.

kkerti kkerti ·

mouse movements are relative, so if you also move your real mouse, the original position might be different

Demetrisag Demetrisag ·

Nice! Yes, the movement will only be relying on the encoder and not account for any movement I do with my mouse 🙂

kkerti kkerti ·

This was way harder than I thought.

kkerti kkerti ·

Check out Mouse Takeover v2.0, I do hope I saved the correct one. You can read in the description section how it works, but copying here as well:
Parameters you can change under init -> self action block:

  • step: Use any integer, best between 1-10. This changes the steps of the mouse imitation.
  • axis: 1 = x, 2 = y, 3 = mouse wheel
  • time: Elapsed time from clicking down the mouse and releasing it. HID mouse or button interactions require releasing the button, you can change how sensitive this should be. Default is set to 400.
  • dir: 1 or -1, use this to invert the movement
  • rTime: Use between 2-10, this is the tuning how fast the reset should complete.
kkerti kkerti ·

This time you should be able to change the dir and axis to get the movement you seek, without changing actually the *-1 placement in the code.

kkerti kkerti ·

This config required a timer to loop over the mouse movement commands, otherwise in a simple for loop it did not work.
I made some status flags, like self._rr which tells the timer that a reset command is running and it should be completed before any other thing happens. The code isn't pretty, but work for now I think, let me know how it feels in action.

if self.axis ~= 3 and self._rr == 0 then
    mouse_button_send(1, 0)
    self._c_act = false
end
if self._rr == 1 then
    local c = rrDir(self.dir, self._mm)
    self._rrC = self._rrC + 1
    if self._rrC < math.abs(self._mm) then
        mouse_move_send(self.axis, self.step * c)
        timer_start(self:element_index(), self.rTime)
    else
        self._mm = 0
        self._rr = 0
        self._rrC = 0
        timer_start(self:element_index(), self.rTime)
    end
end
Demetrisag Demetrisag ·

Wow! This is amazing! I don't know if I manage to be in the studio today to test it out although I will do my best cause now I look forward to it too much. But I gotta say u guys are amazing! Slowly but surely this is turning out to be the best purchase I did in the recent years! I just can't thank you enough. 😀😀

Demetrisag Demetrisag ·

@user I tried searching for a preset on community "mouse takeover v2.0" but couldnt find any. So I just copy pasted the code but that wouldnt do anything

Demetrisag Demetrisag ·

in fact the mouse stopped moving alltogether after I copy pasted the code

Demetrisag Demetrisag ·

oh, I got it! I didnt know I could find more presets in the web, was only looking from inside the grid

Demetrisag Demetrisag ·

Ok, its looking good! Though, is it possible to just go back by its own? without me needing to click the knob? I mean we can set a timer for the click to release and once its release then it can go back!

kkerti kkerti ·

Making it sort of like an automation?

Demetrisag Demetrisag ·

yes! I dont need to have to keep clicking the button to take it back but its better if the script knows its ok to go back once the click is released!

kkerti kkerti ·

You mean make it like a toggle function? If you toggle the encoder, then you

  • change the position
  • wait some time
  • automatically revert to original?
Demetrisag Demetrisag ·

yes! exactly that!

Demetrisag Demetrisag ·

that waiting time should be that 400 number you have

Demetrisag Demetrisag ·

and if I want I could make it less

kkerti kkerti ·

And if it's not toggled, then don't revert?

Demetrisag Demetrisag ·

actually I dont need to a toggle, like a way to activate it if thats what you mean. Cause the first script is working perfectly alright for purposes that I dont want my mouse to snap back. I just need another that I will commit to another knob that this one will reverb back. like always!

Demetrisag Demetrisag ·

am I making it clear?

kkerti kkerti ·

I see. So two separate presets, one which automatically reverts, one which does not.

Demetrisag Demetrisag ·

yes! the first one is working absolutely fine as it is! we could name that mouse control and the 2nd one mouse control which reverts back to original position after drag. The first one is super usefull in applications like sliders or move elements around and the 2nd one is super useful for controlling knobs as those are static but after movement the mouse needs to go back to be able to keep controlling it

Demetrisag Demetrisag ·

controlling knobs with mouse movement is way way more precise than mouse scroll, which is mostly depended on how the programmer made his software to handle mouse scroll movements. Whereas a mouse move is always precise

kkerti kkerti ·

Okay. Understood. I don't know when I can sit back to this, somewhere on this week for sure.

Demetrisag Demetrisag ·

ok perfect! thanks!

Discord

View on Discord

This post is from the Intech Studio Discord community.

Open thread →