Skip to content

Instantly share code, notes, and snippets.

@zhchbin
Created December 4, 2012 07:21
Show Gist options
  • Save zhchbin/4201509 to your computer and use it in GitHub Desktop.
Save zhchbin/4201509 to your computer and use it in GitHub Desktop.
Node-webkit hotkey api proposal(Refactor)
<!DOCTYPE>
<html>
<head>
<title>Hotkey Demo</title>
<script type="text/javascript">
function log(msg) {
document.getElementById('log').textContent += msg + '\n';
}
function error(msg) {
log(JSON.stringify(this) + ": Error, " + msg);
}
function activated() {
log(JSON.stringify(this) + ": Activated");
}
var gui = require('nw.gui');
var hotkey1 = new gui.Hotkey(gui.Hotkey.VKEY_S, gui.Hotkey.Ctrl | gui.Hotkey.Alt);
hotkey1.error = error;
hotkey1.activated = activated;
var hotkey2 = new gui.Hotkey(gui.Hotkey.VKEY_A, gui.Hotkey.Alt);
hotkey2.error = error;
hotkey2.activated = activated;
var hotkey3 = new gui.Hotkey(gui.Hotkey.VKEY_B, gui.Hotkey.Alt);
hotkey3.error = error;
hotkey3.activated = activated;
var hotkey4 = new gui.Hotkey(gui.Hotkey.VKEY_C, gui.Hotkey.Alt);
hotkey4.error = error;
hotkey4.activated = activated;
gui.App.registerGlobalHotkey(hotkey1)
gui.App.registerGlobalHotkey(hotkey2);
gui.App.registerGlobalHotkey(hotkey3);
gui.App.registerGlobalHotkey(hotkey4);
function unregister() {
gui.App.unregisterGlobalHotkey(hotkey2);
gui.App.unregisterGlobalHotkey(hotkey3);
}
</script>
</head>
<body>
<button onclick="unregister()">Click Me to Unregister Hotkey 'Alt + A' and 'Alt + B'</button>
<pre id="log"></pre>
</body>
</html>
{
"name" : "Hotkey-demo",
"main" : "index.html",
"window" : {
"width": 850
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment