Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Summary of the code:</h2> <ul> <li><p>A new instance of <code>KeyMap</code> is created through the <code>new</code> keyword.<br /> Optionally, it's possible to pass an object containing the key map, to bind beforehand:</p> <pre><code>{ "key-combi1": func1, //key-combi such as alt+a, ctrl+c, shift+s "key-combi2": func2, .... "key-combin": funcn //&lt;-- Last property should not end with a comma } </code></pre></li> <li><p>After creating a new instance (<code>var keymap = new Keymap();</code>), the following methods can be used (listened in a logical chronological order):</p> <ol> <li><code>bind</code> - Add additional key binds<br /> <code>keymap.bind( "key-combi", function );</code></li> <li><code>unbind</code> - Remove key bind<br /> <code>keymap.unbind( "key-combi" );</code></li> <li><strong><code>install</code></strong> - Attach key map to element (bound to the <code>keydown</code> event)<br /> <code>keymap.install( element );</code></li> </ol></li> </ul> <h3>Examples</h3> <p>The easiest way to use this method is demonstrated below:</p> <pre><code>var keymap = new Keymap; // Create a new instance of Keymap keymap.bind("ctrl_a", function(event, keyid) { // Bind key combi: ctrl+a alert("Key pressed down! KeyId: " + keyid) }); keymap.install(document.body); // Attach keymap to &lt;body&gt; </code></pre> <p>An alternative way, with the same results:</p> <pre><code>var keymap = new Keymap({ // Create a new instance of Keymap "ctrl_a": function(event, keyid) { // Bind key combi: ctrl+a alert("Key pressed down! KeyId: " + keyid) } }); keymap.install(document.body); // Attach keymap to &lt;body&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload