keyboardshortcuts.html 3.2 KB

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