Skip to content

Instantly share code, notes, and snippets.

@beauwest
Last active May 12, 2016 14:29
Show Gist options
  • Save beauwest/1ba1750003b36134f680f1fd39a231b1 to your computer and use it in GitHub Desktop.
Save beauwest/1ba1750003b36134f680f1fd39a231b1 to your computer and use it in GitHub Desktop.
Example for /dmauro/Keypress/issues/114
<!doctype html>
<meta charset="utf-8">
<script src="http://cdn.rawgit.com/dmauro/Keypress/master/keypress.js"></script>
<script>
window.onload = function () {
var counter = 0,
counterElement = document.getElementById('counter'),
listener = new window.keypress.Listener();
listener.register_combo({
keys: 'esc',
on_keydown: function () {
++counter;
counterElement.textContent = counter;
},
is_solitary: true
});
};
</script>
<h1>Create the hotkey listener</h1>
<pre><code>
var listener = new window.keypress.Listener();
listener.register_combo({
"keys": "esc",
"on_keydown": function () {
++counter;
counterElement.textContent = counter;
},
"is_solitary": true
});
</code></pre>
<h2>Presses: <span id="counter">0</span></h2>
<h2>Steps to reproduce</h2>
<ol>
<li>Press <kbd>escape</kbd> and watch the counter grow.</li>
<li>Turn on <kbd>caps lock</kbd> and press <kbd>escape</kbd> again. Nothing happens.</li>
<li>Leaving caps lock on, refresh the page and press <kbd>escape</kbd> one more time. The counter grows.</li>
</ol>
<p>
This happens with any hotkey where <code>is_solitary</code> is set to <code>true</code>.
</p>
<p>
<a href="https://github.com/dmauro/Keypress/issues/114">View the issue</a> on Github.
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment