1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44

fuchsia_web / webengine / test / data / keyevents.html [blame]

<html>
<body>
<script>
  var keyDicts = [];

  function getActiveModifiers(e) {
    let active_modifiers = [];
    // This list contains all modifiers listed in
    // https://www.w3.org/TR/uievents-key/#keys-modifier (2017). It also
    // includes "OS", which isn't in the spec, but it is listed on the
    // MDN page for getModifierState.
    //
    // Note that several of the listed modifiers aren't yet supported on
    // Fuchsia/Chrome.
    for (modifier of ["Alt", "AltGraph", "CapsLock", "Control", "Fn",
                      "FnLock", "Hyper", "Meta", "NumLock", "OS",
                      "ScrollLock", "Shift", "Super", "Symbol",
                      "SymbolLock"]) {
      if (e.getModifierState(modifier)) {
        active_modifiers.push(modifier);
      }
    }
    return active_modifiers;
  }

  document.addEventListener("keypress", (e) => {
    keyDicts.push( { "key" : e.key, "code" : e.code, "type" : e.type, "repeat": e.repeat, "modifiers": getActiveModifiers(e)});
    document.title = keyDicts.length;
  });

  document.addEventListener("keyup", (e) => {
    keyDicts.push({ "key" : e.key, "code" : e.code, "type" : e.type, "repeat": e.repeat, "modifiers": getActiveModifiers(e)});
    document.title = keyDicts.length;
  });

  document.addEventListener("keydown", (e) => {
    keyDicts.push({ "key" : e.key, "code" : e.code, "type" : e.type, "repeat": e.repeat, "modifiers": getActiveModifiers(e)});
    document.title = keyDicts.length;
  });

  window.onload = function() { document.title = "loaded"; }
</script>
</body>
</html>