FLkeyIn — Reports keys pressed (on alphanumeric keyboard) when an FLTK panel has focus.
FLkeyIn informs about the status of a key pressed by the user on the alphanumeric keyboard when an FLTK panel has got the focus.
kascii - the ascii value of last pressed key. If the key is pressed, the value is positive, when the key is released the value is negative.
FLkeyIn is useful to know whether a key has been pressed on the computer keyboard. The behavior of this opcode depends on the optional ifn argument.
If ifn = 0 (default), FLkeyIn outputs the ascii code of the last pressed key. If it is a special key (ctrl, shift, alt, f1-f12 etc.), a value of 256 is added to the output value in order to distinguish it from normal keys. The output will continue to output the last key value, until a new key is pressed or released. Notice that the output will be negative when a key is depressed.
If ifn is set to the number of an already-allocated table having at least 512 elements, then the table element having index equal to the ascii code of the key pressed is set to 1, all other table elements are set to 0. This allows to check the state of a certain key or set of keys.
Be aware that you must set the ikbdcapture parameter to something other than 0 on a designated FLpanel for FLkeyIn to capture keyboard events from that panel.
Note | |
---|---|
FLkeyIn works internally at k-rate, so it can't be used in the header as other FLTK opcodes. It must be used inside an instrument. |
Here is an example of the FLkeyIn opcode. It uses the file FLkeyIn.csd.
Example 268. Example of the FLkeyIn opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform ; Audio out Audio in No messages -odac -iadc -d ;;;RT audio I/O </CsOptions> <CsInstruments> sr=44100 ksmps=128 nchnls=2 ;Example by Andres Cabrera 2007 FLpanel "FLkeyIn", 400, 300, -1, -1, 5, 1, 1 FLpanelEnd FLrun 0dbfs = 1 instr 1 kascii FLkeyIn ktrig changed kascii if (kascii > 0) then printf "Key Down: %i\n", ktrig, kascii else printf "Key Up: %i\n", ktrig, -kascii endif endin </CsInstruments> <CsScore> i 1 0 120 e </CsScore> </CsoundSynthesizer>