| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 5 |
|
| 6 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 7 |
See the COPYING file for details. |
| 8 |
--> |
| 9 |
<head> |
| 10 |
<title>goog.ui.KeyboardShortcutHandler</title> |
| 11 |
<meta charset="utf-8"> |
| 12 |
<script src="../base.js"></script> |
| 13 |
<script> |
| 14 |
goog.require('goog.dom'); |
| 15 |
goog.require('goog.events.KeyCodes'); |
| 16 |
goog.require('goog.ui.KeyboardShortcutHandler'); |
| 17 |
</script> |
| 18 |
<link rel="stylesheet" href="css/demo.css"> |
| 19 |
</head> |
| 20 |
<body> |
| 21 |
<h1>goog.ui.KeyboardShortcutHandler</h1> |
| 22 |
<div id="text"></div> |
| 23 |
<input type="text" /> |
| 24 |
<input type="checkbox" /> |
| 25 |
<input type="radio" /> |
| 26 |
<button>button</button> |
| 27 |
<textarea></textarea> |
| 28 |
|
| 29 |
<pre> |
| 30 |
Shortcuts: |
| 31 |
A |
| 32 |
T E S T |
| 33 |
Shift+F12 |
| 34 |
Shift+F11 C |
| 35 |
Ctrl+A |
| 36 |
G O O G |
| 37 |
B C |
| 38 |
B D |
| 39 |
Alt+Q A |
| 40 |
Alt+Q Shift+A |
| 41 |
Alt+Q Shift+B |
| 42 |
Space |
| 43 |
Home |
| 44 |
Enter |
| 45 |
G S |
| 46 |
S |
| 47 |
Meta+y |
| 48 |
</pre> |
| 49 |
|
| 50 |
<script> |
| 51 |
|
| 52 |
function showTriggered(event) { |
| 53 |
goog.dom.setTextContent(document.getElementById('text'), |
| 54 |
'Shortcut triggered: ' + event.identifier); |
| 55 |
} |
| 56 |
|
| 57 |
var shortcutHandler = new goog.ui.KeyboardShortcutHandler(document); |
| 58 |
|
| 59 |
var NONE = goog.ui.KeyboardShortcutHandler.Modifiers.NONE; |
| 60 |
var CTRL = goog.ui.KeyboardShortcutHandler.Modifiers.CTRL; |
| 61 |
var SHIFT = goog.ui.KeyboardShortcutHandler.Modifiers.SHIFT; |
| 62 |
var ALT = goog.ui.KeyboardShortcutHandler.Modifiers.ALT; |
| 63 |
var META = goog.ui.KeyboardShortcutHandler.Modifiers.META; |
| 64 |
|
| 65 |
shortcutHandler.registerShortcut('A', 'a'); |
| 66 |
shortcutHandler.registerShortcut('T E S T', 't e s t'); |
| 67 |
shortcutHandler.registerShortcut('SHIFT_F12', 'shift+f12'); |
| 68 |
shortcutHandler.registerShortcut('SHIFT_F11 C', 'shift+f11 c'); |
| 69 |
shortcutHandler.registerShortcut('META_Y', 'meta+y'); |
| 70 |
shortcutHandler.registerShortcut('G S', 'g s'); |
| 71 |
shortcutHandler.registerShortcut('S', 's'); |
| 72 |
|
| 73 |
shortcutHandler.registerShortcut('GOOG', |
| 74 |
goog.events.KeyCodes.G, NONE, |
| 75 |
goog.events.KeyCodes.O, NONE, |
| 76 |
goog.events.KeyCodes.O, NONE, |
| 77 |
goog.events.KeyCodes.G); |
| 78 |
|
| 79 |
shortcutHandler.registerShortcut('CTRL_A', |
| 80 |
goog.events.KeyCodes.A, CTRL); |
| 81 |
|
| 82 |
shortcutHandler.registerShortcut('BC', |
| 83 |
goog.events.KeyCodes.B, NONE, |
| 84 |
goog.events.KeyCodes.C); |
| 85 |
|
| 86 |
shortcutHandler.registerShortcut('BD', |
| 87 |
goog.events.KeyCodes.B, NONE, |
| 88 |
goog.events.KeyCodes.D); |
| 89 |
|
| 90 |
shortcutHandler.registerShortcut('ALT_Q A', |
| 91 |
goog.events.KeyCodes.Q, ALT, |
| 92 |
goog.events.KeyCodes.A); |
| 93 |
|
| 94 |
shortcutHandler.registerShortcut('ALT_Q SHIFT_A', |
| 95 |
goog.events.KeyCodes.Q, ALT, |
| 96 |
goog.events.KeyCodes.A, SHIFT); |
| 97 |
|
| 98 |
shortcutHandler.registerShortcut('ALT_Q SHIFT_B', [ |
| 99 |
goog.events.KeyCodes.Q, ALT, |
| 100 |
goog.events.KeyCodes.B, SHIFT]); |
| 101 |
|
| 102 |
shortcutHandler.registerShortcut('SPACE', goog.events.KeyCodes.SPACE); |
| 103 |
shortcutHandler.registerShortcut('HOME', goog.events.KeyCodes.HOME); |
| 104 |
shortcutHandler.registerShortcut('ENTER', goog.events.KeyCodes.ENTER); |
| 105 |
|
| 106 |
goog.events.listen( |
| 107 |
shortcutHandler, |
| 108 |
goog.ui.KeyboardShortcutHandler.EventType.SHORTCUT_TRIGGERED, |
| 109 |
showTriggered); |
| 110 |
</script> |
| 111 |
</body> |
| 112 |
</html> |