I catch key strokes

Trying to get the Keystroke to work .
The tutorial uses the j key ( which in the code uses keystate nr"38 ; but on my pc is uses keystate nr 74 , both in qwerty and azerty mode .
I replaced the keystate nr38 with 81 ( which is q ) , executing the code and typing q while the (catching ) window is openend …
Console view recognizes the nr ,but no sound at all .
The keystroke nr , controls the sineosc mul value

(
w = Window.new("I catch keystrokes");
w.view.keyDownAction = { arg view, char, modifiers, unicode, keycode;  [char, keycode].postln; };
w.front;
)

// then execute this and then press the 'j' key
(
w.front; // something safe to type on
{ SinOsc.ar(800, 0, KeyState.kr(81, 0, 0.4)) }.play;
)

///

Hello!

The following post may help you:

Testing in Linux, I found accidentally that the KeyState code 38 from the original helpfile example corresponds to lowercase s.

:flushed:

BUT – this is important – I use a customized mirror-image Dvorak keyboard layout, which places the character s on the A key. On another Ubuntu/debian machine, 38 might be a. I don’t know.

This appears to have no relationship to keycodes or Unicode passed into a keyDownAction.

So my best advice for the moment is to try all the keys until something happens.

BTW in Windows, you’re SOL: [plugins] KeyState UGen not working properly · Issue #4663 · supercollider/supercollider · GitHub – “KeyState is not implemented on Windows, it seems, looking at the code.”

That comment comes from a bug report filed about KeyState problems: [plugins] KeyState UGen not working properly · Issue #4663 · supercollider/supercollider · GitHub

hjh

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, kAct, lastPressed;
	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, \o:13, \l:14,
		\p:15, ';':16);
	n = k.size;
	x = { |i|
		{ |g = 0|
			LFTri.ar((i + 69 + [0, 0.15]).midicps)
			* 0.1
			* Env.adsr.kr(gate:g);
		}.play
	}!n;
	ctl = { |i=0, gate=0|
		x[i].set(\g, gate)
	};
	w = Window("self ear-training", Rect(200, 200, 583, 136));
	w.front;
	w.onClose_{ { |i| x[i].free }!n };
	b = { |parent, label|
		Button(parent, 30@30)
		.states_([
			[label],
			[label, Color.white, Color.grey]
		])
		.mouseDownAction_{
			lastPressed = label;
			ctl.(label, 1);
			bs[label].value = 1
		}
		.action_{
			ctl.(label, 0);
			bs[label].value = 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;
	kAct = { |c, v|
		c = c.asSymbol;
		(k.includesKey(c) != false).if{
			ctl.(k[c], v);
			bs[k[c]].value = v
		}
	};
	StaticText(w, 572@60).string_("Press, hold and then release the keys under the numbered buttons using"
		+ "your computer keyboard. Alternatively, you might press, hold, and then release each button using"
		+ "the left button of the computer mouse. The multi-touch on touchscreen may function, but it"
		+ "hasn't been tested.");
	w.view
	.keyDownAction_{ |view, char|
		kAct.(char, 1)
	}
	.keyUpAction_{ |view, char, mod, unicode, keycode, key|
		kAct.(char, 0)
	}
	.mouseUpAction_{ //|view, x, y, modifiers, buttonNumber|
		var lastPressedK = k.findKeyForValue(lastPressed);
		kAct.(lastPressedK, 0)
	}
}
)