I want to use MouseDown in SuperCollider and am having a helluva time. Is it the case that only mouseDownAction actually works with anything? I want to be able to click anywhere on the screen, and have the mouse coordinates print, e.g., to the post window:
Server.default=s=Server.local;
s.boot;
s.mouseDownAction = { x = {|t_poll=0| var x_val, y_val;
x_val = {MouseX.kr};
y_val = {MouseY.kr};
Poll.kr(t_poll, [x_val, y_val], ["x_val", "y_val"]);
}.play };
s.mouseUpAction = { x.set(\t_poll,1) };
Of course, this does not work, because mouseDownAction seems reserved as a property of the 'View' class i.e. only clicking within a specific window, as the below working [albeit not quite what I want] code:
w = Window.new("Mouse Coordinates", Rect(1300,600,50,50));
b = Button.new(w,Rect(10,10,40,25)).states_([["off"],["on"]]);
b.mouseDownAction = { x = {|t_poll=0| var x_val, y_val;
x_val = {MouseX.kr};
y_val = {MouseY.kr};
Poll.kr(t_poll, [x_val, y_val], ["x_val", "y_val"]);
}.play };
b.mouseUpAction = { x.set(\t_poll,1) };
w.front;
Some things I want to know:
- Can I modify the first snippet to actually work?
- Is there a way to get MouseDown to work to give me these coordinates as I click anywhere on the screen?
- How can I figure out how to 'get' the mouse coordinates (calling on which functions [already tried 'output', 'postln', &.c])?
Thanks!!!
There is a Ugen for the mouse button https://doc.sccode.org/Classes/MouseButton.html
This is the example from the linked helpfile:
What you could do is have the server generate an OSC message when the button is pressed and have the language listen for that.