Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-release > by-pkgid > b707d9a4ee443103660a75ccb6e51334 > files > 2559

csound-doc-5.19.01-10.mga5.noarch.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>sensekey</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.76.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="sense.html" title="sense" />
    <link rel="next" href="serialBegin.html" title="serialBegin" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">sensekey</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="sense.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="serialBegin.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry" title="sensekey">
      <a id="sensekey"></a>
      <div class="titlepage"></div>
      <a id="IndexSensekey" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">sensekey</span>
        </h2>
        <p>sensekey — 
      Returns the ASCII code of a key that has been pressed.
    </p>
      </div>
      <div class="refsect1" title="Description">
        <a id="idp41878368"></a>
        <h2>Description</h2>
        <p>
      Returns the ASCII code of a key that has been pressed, or -1 if no key has been pressed.
    </p>
      </div>
      <div class="refsect1" title="Syntax">
        <a id="idp41879184"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">kres[, kkeydown] <span class="command"><strong>sensekey</strong></span></pre>
      </div>
      <div class="refsect1" title="Performance">
        <a id="idp41880216"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kres</em></span> - returns the ASCII value of a key which is pressed or released.
    </p>
        <p>
      <span class="emphasis"><em>kkeydown</em></span> - returns 1 if the key was pressed, 0 if it was released or if there is no key event.
    </p>
        <p>
      <span class="emphasis"><em>kres</em></span> can be used to read keyboard events from stdin and returns the ASCII value of any key that is pressed or released, or it returns -1 when there is no keyboard activity. The value of <span class="emphasis"><em>kkeydown</em></span> is 1 when a key was pressed, or 0 otherwise. This behavior is emulated by default, so a key release is generated immediately after every key press. To have full functionality, FLTK can be used to capture keyboard events. <a class="link" href="FLpanel.html" title="FLpanel"><em class="citetitle">FLpanel</em></a> can be used to capture keyboard events and send them to the sensekey opcode, by adding an additional optional argument. See <a class="link" href="FLpanel.html" title="FLpanel"><em class="citetitle">FLpanel</em></a> for more information.
    </p>
        <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note: Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        This opcode can also be written as <a class="link" href="sense.html" title="sense"><em class="citetitle">sense</em></a>.
      </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="refsect1" title="Examples">
        <a id="idp41904576"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the sensekey opcode. It uses the file <a class="ulink" href="examples/sensekey.csd" target="_top"><em class="citetitle">sensekey.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp41905568"></a>
          <p class="title">
            <strong>Example 751. Example of the sensekey opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in</span>
-odac           -iadc    <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o sensekey.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">kr</span> <span class="op">=</span> 4410
<span class="ohdr">ksmps</span> <span class="op">=</span> 10
<span class="ohdr">nchnls</span> <span class="op">=</span> 1

<span class="comment">; Instrument #1.</span>
<span class="oblock">instr</span> 1
  k1 <span class="opc">sensekey</span>
  <span class="opc">printk2</span> k1
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">; Play Instrument #1 for thirty seconds.</span>
<span class="stamnt">i</span> 1 0 30
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      Here is what the output should look like when the "q" button is pressed...
      </p>
        <pre class="screen">
q i1   113.00000
      </pre>
        <p>
    </p>
        <p>
      Here is an example of the sensekey opcode in conjucntion with <a class="link" href="FLpanel.html" title="FLpanel"><em class="citetitle">FLpanel</em></a>. It uses the file <a class="ulink" href="examples/FLpanel-sensekey.csd" target="_top"><em class="citetitle">FLpanel-sensekey.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp41909400"></a>
          <p class="title">
            <strong>Example 752. Example of the sensekey opcode using keyboard capture from an FLpanel.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o FLpanel-sensekey.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="comment">; Example by Johnathan Murphy</span>

  <span class="ohdr">sr</span>	    <span class="op">=</span>  44100
  <span class="ohdr">ksmps</span>	    <span class="op">=</span>  128
  <span class="ohdr">nchnls</span>    <span class="op">=</span>  2


	<span class="comment">; ikbdcapture flag set to 1</span>
  ikey	    <span class="opc">init</span>      1 		
 
	    <span class="opc">FLpanel</span>   "sensekey", 740, 340, 100, 250, 2, ikey
  gkasc, giasc	<span class="opc">FLbutBank</span>	2, 16, 8, 700, 300, 20, 20, <span class="op">-</span>1
	    <span class="opc">FLpanelEnd</span>
	    <span class="opc">FLrun</span>

    <span class="oblock">instr</span> 1

  kkey	    <span class="opc">sensekey</span>
  kprint    <span class="opc">changed</span>   kkey
	    <span class="opc">FLsetVal</span>  kprint, kkey, giasc

    <span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span>1 0 60
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      The lit button in the FLpanel window shows the last key pressed.
    </p>
        <p>
      Here is a more complex example of the sensekey opcode in conjucntion with <a class="link" href="FLpanel.html" title="FLpanel"><em class="citetitle">FLpanel</em></a>. It uses the file <a class="ulink" href="examples/FLpanel-sensekey.csd" target="_top"><em class="citetitle">FLpanel-sensekey2.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp41911576"></a>
          <p class="title">
            <strong>Example 753. Example of the sensekey opcode using keyboard capture from an FLpanel.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac         <span class="comment">; -iadc     -d     ;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o FLpanel-sensekey2.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="ohdr">sr</span> <span class="op">=</span>  48000
<span class="ohdr">ksmps</span> <span class="op">=</span>  32
<span class="ohdr">nchnls</span> <span class="op">=</span>  1
<span class="comment">; Example by Istvan Varga</span>
<span class="comment">; if the FLTK opcodes are commented out, sensekey will read keyboard</span>
<span class="comment">; events from stdin</span>
        <span class="opc">FLpanel</span> "", 150, 50, 100, 100, 0, 1
        <span class="opc">FLlabel</span> 18, 10, 1, 0, 0, 0
        <span class="opc">FLgroup</span> "Keyboard Input", 150, 50, 0, 0, 0
        <span class="opc">FLgroupEnd</span>
        <span class="opc">FLpanelEnd</span>

        <span class="opc">FLrun</span>

        <span class="oblock">instr</span> 1

ktrig1 <span class="opc">init</span> 1
ktrig2 <span class="opc">init</span> 1
<span class="olabel">nxtKey1</span><span class="op">:</span>
k1, k2 <span class="opc">sensekey</span>
        <span class="octrl">if</span> (k1 <span class="op">!=</span> <span class="op">-</span>1 <span class="op">||</span> k2 <span class="op">!=</span> 0) then
        <span class="opc">printf</span> "Key code <span class="op">=</span> <span class="op">%</span>02X, state <span class="op">=</span> <span class="op">%</span>d\n", ktrig1, k1, k2
ktrig1 <span class="op">=</span>  3 <span class="op">-</span> ktrig1
        <span class="octrl">kgoto</span> <span class="olabel">nxtKey1</span>
        <span class="octrl">endif</span>
<span class="olabel">nxtKey2</span><span class="op">:</span>
k3 <span class="opc">sensekey</span>
        <span class="octrl">if</span> (k3 <span class="op">!=</span> <span class="op">-</span>1) then
        <span class="opc">printf</span> "Character <span class="op">=</span> '<span class="op">%</span>c'\n", ktrig2, k3
ktrig2 <span class="op">=</span>  3 <span class="op">-</span> ktrig2
        <span class="octrl">kgoto</span> <span class="olabel">nxtKey2</span>
        <span class="octrl">endif</span>

        <span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 3600
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
      The console output will look something like:
</p>
        <div class="literallayout">
          <p><br />
new alloc for instr 1:<br />
Key code = 65, state = 1<br />
Character = 'e'<br />
Key code = 65, state = 0<br />
Key code = 72, state = 1<br />
Character = 'r'<br />
Key code = 72, state = 0<br />
Key code = 61, state = 1<br />
Character = 'a'<br />
Key code = 61, state = 0<br />
</p>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1" title="See also">
        <a id="idp41913392"></a>
        <h2>See also</h2>
        <p>
      <a class="link" href="FLpanel.html" title="FLpanel"><em class="citetitle">FLpanel</em></a>,
      <a class="link" href="FLkeyIn.html" title="FLkeyIn"><em class="citetitle">FLkeyIn</em></a>
    </p>
      </div>
      <div class="refsect1" title="Credits">
        <a id="idp41914952"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: John ffitch</td>
          </tr>
          <tr>
            <td>University of Bath, Codemist. Ltd.</td>
          </tr>
          <tr>
            <td>Bath, UK</td>
          </tr>
          <tr>
            <td>October 2000</td>
          </tr>
        </table>
        <p>
    </p>
        <p>Examples written by Kevin Conder, Johnathan Murphy and Istvan Varga.</p>
        <p>New in Csound version 4.09. Renamed in Csound version 4.10.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="sense.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="serialBegin.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">sense </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> serialBegin</td>
        </tr>
      </table>
    </div>
  </body>
</html>