Ah, is KeyState still not implemented on Windows?
I remember having problems with it some years ago because KeyState was not implemented on Windows.
I had to find other possibilities to control synth using keys on the computer keyboard.
The code below is from my old drafts at that time used to build a one-octave keyboard. Could it be useful for @gentleclockdivider?
(
s.waitForBoot{
var w, n, b, bs, k, ks, x, lay, ctl;
n = 13;
x = { |i|
{ |g = 0|
LFTri.ar((69 + i).midicps * [1, 1.01])
* 0.1
* Env.adsr.kr(gate:g);
}.play } ! n;
ctl = { |i=0, gate=0|
x[i].set(\g, gate.postln) };
w = Window("self ear-training", Rect(200, 200, 448, 136));
w.front;
w.onClose_{ { |i| x[i].free } ! n };
k = (\a:0, \w:1, \s:2, \e:3, \d:4, \f:5, \t:6, \g:7, \y:8, \h:9, \u:10, \j:11, \k:12);
// k = ( \q:0, \w:1, \e:2, \r:3, \t:4, \y:5, \u:6, \i:7, \o:8, \p:9, '[':10, ']':11, '\\':12 );
b = { |parent, label|
Button(parent, 30@30)
.states_([[label]])
.mouseDownAction_{ ctl.(label, 1) }.action_{ ctl.(label, 0) }
};
lay = w.addFlowLayout;
bs = { |i| b.(w, i) }!n;
lay.nextLine;
ks = { |i|
StaticText(w, 30@30)
.string_(k.findKeyForValue(i))
.align_(\center) }!n;
w.view
.keyDownAction_{
|view, char|
(k.trueAt(char.asSymbol)!=false).if{
ctl.(k[char.asSymbol], 1)
}
}
.keyUpAction_{
|view, char, mod, unicode, keycode, key|
(k.trueAt(char.asSymbol)!=false).if{
ctl.(k[char.asSymbol], 0)
}
};
StaticText(w, 448@60).string_("Press the key under each number.")
}
)