Removing default keyDown mappings (specifically 'x' for value 1.0

Yello, this is my first post/question - I hope this is the right place to be posting/questioning. I am building an interactive program which uses key mappings to control parameters. The problem I am facing is that the default key mappings override mine when assigning ‘x’ to a decrease in slider value. Is there a way to override the overriding?

Absolutely, welcome!

The relevant part of the documentation is here: View | SuperCollider 3.12.2 Help – but I think it’s not explained very well, so…

There are two kinds of key responses: user-specified (keyDownAction) and default (implemented in C++ in the backend). Additionally, keystrokes may be passed upward to the view’s parent.

When a View (e.g. Slider) responds to a keystroke (or mouse action), the first thing that happens is that it calls the keyDownAction of whichever widget has focus at the moment. What happens next depends on the return value of the keyDownAction function:

  • If this function returns a Boolean, then this tells the system “I have already handled the keystroke; do NOT perform the default C++ actions.”
    • true: “I have completely handled the keystroke – do not do the default actions, and do not pass the keystroke up to the parent.”
    • false: “This view is not interested in this keystroke – do not do the default actions, but do pass the keystroke up to the parent.”
  • If this function returns anything else, then it tells the system to go ahead with the default C++ actions. At this stage, one of two things will happen:
    • If this view has a default action for this key, then the view will do that and swallow the keystroke.
    • If it does not have a default action for this key, then it will pass the key up to the parent.
(
v = View(nil, Rect(800, 200, 300, 300)).front;
v.layout = VLayout(
	w = Slider2D()
);
w.action = { |view| [view.x, view.y].postln };
v.keyDownAction = { |view, char, modifiers, unicode, keycode|
	"parent view keycode = %\n".postf(keycode);
};
)

// default: arrow keys are active
// and Slider2D "eats" the arrow keys
// (v.keyDownAction doesn't fire)
// but if you hit a non-active key like 'g'
// then the parent View's keyDownAction works

(
w.keyDownAction = { |view, char, modifiers, unicode, keycode|
	"keycode = %\n".postf(keycode);
	// returned nil: default C++ key actions still fire
	// and the keys do NOT bubble up to the parent
	nil
};
)

(
w.keyDownAction = { |view, char, modifiers, unicode, keycode|
	"keycode = %\n".postf(keycode);
	// returned false: default C++ key actions do not fire
	// and the keys DO bubble up to the parent
	false
};
)

(
w.keyDownAction = { |view, char, modifiers, unicode, keycode|
	"keycode = %\n".postf(keycode);
	// returned true: default C++ key actions do not fire
	// and the keys do NOT bubble up to the parent
	true
};
)

So it might be like this:

mySlider.keyDownAction = { |view, char|
	if(char == $x) {
		false  // don't act, pass it up
	} {
		nil  // other keys, normal action
	}
};

hjh

This is amazing, can’t thank you enough! Problem solved, happy new year :boom: