## SwingOSC – Java-based GUI classes

This class is meant as an emulation of the KeyState UGen. last mod: 10-apr-07 sciss
This class replaces the UGen by a control bus reader. It does not really track the keyboard ; instead you can write the virtual key states (0 or 1) onto this control bus or use a GUI panel as shown in the example code below.

different behaviour
class | this is not a UGen subclass, so in rare circumstances there are incompatibilities
keycodes | these are essentially different from the cocoa equivalents. for example, in cocoa the 'j' character has a keycode of 38, in SwingOSC that's 74

# JKeyState

Note: please use the abstraction layer GUI.keyState if possible! (see GUI)

`JKeyState` manufactures a UGen that responds to keyboard presses and releases.

Method signatures

    	JKeyState.kr( <keycode = 0>, <minval = 0>, <maxval = 1>, <lag = 0.2> )

- `keycode` – The keycode value of the key to check. This corresponds to the keycode values passed into the `keyDownAction`s of JSCViews. See example below.
- `minval` – The value to output when the key is not pressed.
- `maxval` – The value to output when the key is pressed.
- `lag` – A lag (portamento) factor. See Lag for details.

See also JMouseButton, JMouseX, JMouseY.

Examples:

    s.boot;

    // execute the code below to find out a key's keycode
    // the char and keycode of any key you press will be printed in the post window
    (
    w = JSCWindow( "I catch keystrokes" );
    w.view.keyDownAction = { arg view, char, modifiers, unicode, keycode;  [char, keycode].postln; };
    w.view.canFocus = true;
    w.view.focus;
    w.front;
    )

    // example synth reacting to the 'j' key
    (
    { SinOsc.ar(800, 0, JKeyState.kr(74, 0, 0.1)) }.play;
    )

    // either set the key programmatically ...
    JKeyState.set( 74, 1 );
    JKeyState.set( 74, 0 );

    // ... or type in the control GUI
    JKeyState.makeGUI;