1/**
2 * Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7var KEY_MAP = {
8  12: 'Clear',
9  14: 'Enter',
10  33: 'PgUp',
11  34: 'PgDown',
12  35: 'End',
13  36: 'Home',
14  37: 'Left',
15  38: 'Up',
16  39: 'Right',
17  40: 'Down',
18  45: 'Insert',
19  46: 'Delete',
20  96: 'Numpad0',
21  97: 'Numpad1',
22  98: 'Numpad2',
23  99: 'Numpad3',
24  100: 'Numpad4',
25  101: 'Numpad5',
26  102: 'Numpad6',
27  103: 'Numpad7',
28  104: 'Numpad8',
29  105: 'Numpad9',
30  106: '*',
31  107: 'Plus',
32  108: '_',
33  109: '-',
34  111: '/',
35  112: 'F1',
36  113: 'F2',
37  114: 'F3',
38  115: 'F4',
39  116: 'F5',
40  117: 'F6',
41  118: 'F7',
42  119: 'F8',
43  120: 'F9',
44  121: 'F10',
45  122: 'F11',
46  123: 'F12',
47  124: 'F13',
48  125: 'F14',
49  126: 'F15',
50  186: ';',
51  187: '=',
52  188: ',',
53  189: '-',
54  190: '.',
55  191: '/',
56  192: '`',
57  219: '[',
58  221: ']'
59};
60
61var isMac = (navigator.appVersion.indexOf("Mac") != -1);
62
63function keyEventToString(evt) {
64  var tokens = [];
65  if (evt.ctrlKey) {
66    tokens.push('Control');
67  }
68  if (evt.altKey) {
69    tokens.push(isMac ? 'Option' : 'Alt');
70  }
71  if (evt.metaKey) {
72    tokens.push(isMac ? 'Command' : 'Meta');
73  }
74  if (evt.shiftKey) {
75    tokens.push('Shift');
76  }
77  if (evt.keyCode >= 48 && evt.keyCode <= 90) {
78    tokens.push(String.fromCharCode(evt.keyCode));
79  } else if (KEY_MAP[evt.keyCode]) {
80    tokens.push(KEY_MAP[evt.keyCode]);
81        } else {
82    return '';
83        }
84  return tokens.join('+');
85}
86
87function getDefaultKeyString() {
88  return keyEventToString({
89    keyCode: 83,  // 's'
90    shiftKey: true,
91    altKey: true,
92    ctrlKey: true,
93    metaKey: false});
94}
95