Is it possible to add action to mouseDownAction on EZKnob?

I’d like to add an action to the existing ones on EZKnob, but it seems that the value is being set after passing through mouseDownAction.

Consider this code:

(
var window = Window("Cmd+Click Test", 200@200).front;
var knob = EZKnob(window, 100@150, "Test", [-1.0, 1.0].asSpec,
    action: { |ez| postf("set to %\n", ez.value) },
    initValue: 0.0
);
knob.knobView.mouseDownAction = { |view, x, y, modifiers, buttonNumber, clickCount|
    if ((modifiers == 262144) and: (buttonNumber == 1)) {
        knob.valueAction = 0.0; // Reset to 0.0 when Ctrl is pressed
    };
};
)

Here is what i see in POST window:

set to 0.0
set to -0.33049280839934

So, the code works, but the actual setting of the value occurs AFTER mouseDownAction. Is there a way to override this behaviour?

On this Windows machine, I couldn’t get it work with the Ctrl key, but it works ok with Shift key if you add the defer function to delay the command:

(
var window = Window("Cmd+Click Test", 200@200).front;
var knob = EZKnob(window, 100@150, "Test", [-1.0, 1.0].asSpec,
    action: { |ez| postf("set to %\n", ez.value) },
    initValue: 0.0
);
knob.knobView.mouseDownAction = { |view, x, y, modifiers, buttonNumber, clickCount|
    if ((modifiers  == 131072 ) and: (buttonNumber == 1)) {
        {
			knob.valueAction = 0.0; // Reset to 0.0 when Shift is pressed
		}.defer(0.1);
    };
};
)

Best,
Paul

1 Like

great, thanks!!

actually on my mac it allows that with Ctrl and with a significantly shorter delay - this code works fine:

        if ((modifiers == 262144) and: (buttonNumber == 1)) {
            { knob.valueAction = 0.0 }.defer(0.01)
        };

But it took me quite some time to realize that the change of the value was due to the returning to the previous value when the mouse is released. So, mouseDownAction sets it to 0, but then on mouseUpAction a new value being set. So, changing it to mouseUpAction removed the necessity of deferring:

(
var window = Window("Cmd+Click Test", 200@200).front;
var knob = EZKnob(window, 100@150, "Test", [-1.0, 1.0].asSpec,
    action: { |ez| postf("set to %\n", ez.value) },
    initValue: 0.0
);

// Using mouseUpAction prevents returning to the previous value when the mouse is released
knob.knobView.mouseUpAction = { |view, x, y, modifiers, buttonNumber, clickCount|
    if ((modifiers == 262144) and: (buttonNumber == 1)) {
        knob.valueAction = 0.0
    };
};
)

best,
denis

1 Like