Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twolfson/9480774 to your computer and use it in GitHub Desktop.
Save twolfson/9480774 to your computer and use it in GitHub Desktop.
Proof of concept for media keys in node-webkit
<!DOCTYPE html>
<html>
<head>
<title>Media key press test</title>
</head>
<body>
<h1>Key pressed</h1>
<p id="output">null</p>
<script>
(function () {
// Load in dependencies
var gui = require('nw.gui');
// Grab the output element
var $output = document.getElementById('output');
console.log('wat');
// Define a shortcut
// https://github.com/rogerwang/node-webkit/pull/1735/files#diff-2c0e331a5f16a997364d359a556b5acdR36
// https://github.com/rogerwang/node-webkit/pull/1735/files#diff-a392d93e2592c5b8119a1fba725e9f5aR10
var shortcut = new gui.Shortcut({
key: 'Alt+Shift+X',
active: function () {
$output.textContent = 'Shortcut activated';
},
failed: function () {
$output.textContent = 'Failed to bind shortcut';
}
});
gui.App.registerGlobalHotKey(shortcut);
}());
</script>
</body>
</html>
{
"name": "gist-node-webkit-media-keys",
"main": "index.html"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment