System.register(["src/client/lang/utils.js"], function (_export, _context) {
  "use strict";

  var extend, KeyInput, __SystemJSRewritingHack, CONTEXT;
  return {
    setters: [function (_srcClientLangUtilsJs) {
      extend = _srcClientLangUtilsJs.extend;
    }],
    execute: function () {
      __SystemJSRewritingHack = {};
      _recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_keys_input_js = _recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_keys_input_js || {};
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_keys_input_js, "extend", {
        get() {
          return extend;
        },
        set(thisIsVererySecretVariableName) {
          extend = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      CONTEXT = 'key-state';
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_keys_input_js, "CONTEXT", {
        get() {
          return CONTEXT;
        },
        set(thisIsVererySecretVariableName) {
          CONTEXT = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      extend(KeyboardEvent.prototype, {
        get ctrlRight() {
          return !!self.input.key('ControlRight');
        },
        get shiftRight() {
          return !!self.input.key('ShiftRight');
        },
        get altRight() {
          return !!self.input.key('AltRight');
        }
      });
      KeyInput = class KeyInput {
        constructor() {
          this._resetStates();
        }

        /*MD ## querying state key MD*/
        // #TODO: bind actions to keys
        state(action) {
          throw new Error('not yet implemented');
        }
        key(code) {
          return !!this._keys[code];
        }
        allKeys() {
          return Object.keys(input._keys);
        }

        /*MD ## writing key state MD*/
        _setKey(code, state) {
          if (state) {
            this._keys[code] = true;
          } else {
            delete this._keys[code];
          }
        }
        _resetStates() {
          this._keys = {};
        }

        /*MD ## hooks MD*/
        static setKeyState(e, state) {
          self.input._setKey(e.code, state);
        }
        static onKeydown(e) {
          this.setKeyState(e, true);
        }
        static onKeyup(e) {
          this.setKeyState(e, false);
        }
        static onFocus(e) {
          self.input._resetStates();
        }

        // #important
        static load() {
          self.input = new this();
          const options = {
            capture: true,
            passive: true
          };
          lively.removeEventListener(CONTEXT);
          lively.addEventListener(CONTEXT, document, "keydown", this.onKeydown.bind(this), options);
          lively.addEventListener(CONTEXT, document, "keyup", this.onKeyup.bind(this), options);
          lively.addEventListener(CONTEXT, window, 'focus', this.onFocus.bind(this), options);
        }
      };
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_keys_input_js, "KeyInput", {
        get() {
          return KeyInput;
        },
        set(thisIsVererySecretVariableName) {
          KeyInput = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      KeyInput.load();
    }
  };
});