How to use the keycode.names function in keycode

To help you get started, we’ve selected a few keycode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github instructure / instructure-ui / packages / ui-forms / src / Select / SelectField / index.js View on Github external
handleKeyDown = event => {
    const key = keycode.names[event.keyCode]
    // eslint-disable-next-line no-prototype-builtins
    if (this.keyMap.hasOwnProperty(key)) {
      if ((key !== 'enter' || this.expanded) && key !== 'space') {
        event.preventDefault()
      }
      this.keyMap[key](event)
    } else {
      // return dom focus to input when the user tries to type
      if (this._input && this.props.editable) {
        this._input.focus()
      }
    }
    if (key === 'tab') {
      // return focus to input and back into natural tab order
      this._input.focus()
    }
github instructure / instructure-ui / packages / ui-selectable / src / Selectable / index.js View on Github external
handleKeyUp = (event) => {
    const { isShowingOptions } = this.props
    const key = keycode.names[event.keyCode]

    if (key === 'esc') {
      if (isShowingOptions) {
        // if options showing, hide them
        this.handleOpenClose(event)
      }
    }
  }
github crowbartools / Firebot / gui / js / interactive / json-importer.js View on Github external
function convertBeamJson() {
    var activeProfile = $('.interactive-board-select option:selected').val();   
    var dbControls = new JsonDB('./user-settings/controls/' + activeProfile, true, false);

    var beamJson = $('.json-import-area').val();

    try {
        var beamParsed = JSON.parse(beamJson);
        var beamTactiles = beamParsed.tactiles;
        // Cycle through and grab tactile information.
        for (var i = 0, length = beamTactiles.length; i < length; i++) {
            var button = beamTactiles[i];
            var buttonid = button.id;
            var buttonKeyNum = button.key;
            var keypress = keycode.names[buttonKeyNum];
            var buttonText = button.text;
            var movementCounter = "";
            var cooldown = button['cooldown'].press;
            var holding = button.analysis['holding'];
            var frequency = button.analysis['frequency'];

            // If there is no button text, then we'll set a default.
            if(buttonText === undefined){
                var buttonText = "Button "+buttonid;
            }

            // Check to make sure keycode module didn't blow it. If it did, just use the beam key name.
            if (keypress === undefined || keypress === null) {
                var keypress = buttonKeyNum;
            }
github instructure / instructure-ui / packages / ui-selectable / src / Selectable / index.js View on Github external
handleKeyDown = (event) => {
    const {
      isShowingOptions,
      highlightedOptionId,
      onRequestHighlightOption,
      onRequestHighlightFirstOption,
      onRequestHighlightLastOption,
      onRequestSelectOption
    } = this.props

    const key = keycode.names[event.keyCode]

    switch (key) {
      case 'space':
        if (!isShowingOptions) {
          // if options hidden, show them
          this.handleOpenClose(event)
        }
        break
      case 'enter':
        if (highlightedOptionId) {
          // select highlighted option
          event.preventDefault()
          onRequestSelectOption(event, { id: highlightedOptionId })
        }
        break
      case 'down':
github instructure / instructure-ui / packages / ui-forms / src / Select / SelectField / index.js View on Github external
handleKeyUp = event => {
    const key = keycode.names[event.keyCode]
    if (key === 'esc' && this.expanded) {
      event.preventDefault()
      // ensure focus returns to input
      if (this._input) {
        this._input.focus()
      }
      this.close(event)
    }
    this.props.onKeyUp(event)
  }
github timoxley / keycode / test / keycode.js View on Github external
it('exposes keycode/name maps', function() {
  for (var code in keycode.codes) {
    assert.strictEqual(keycode(code), keycode(keycode.names[keycode.codes[code]]))
  }
})
github drhayes / blaster / src / states / instructions.js View on Github external
    let moveLabels = moveKeys.map((key) => keycode.names[keyConfig[key]].toUpperCase()).join(', ');
    this.makeText(this.game.world.centerY * 0.6, `${moveLabels} to move.`);
github drhayes / blaster / src / states / mainMenu.js View on Github external
this.makeButton(this.game.world.centerX, this.game.world.centerY, 'Options', () => {
      this.game.state.start('options');
    });
    this.makeButton(this.game.world.centerX, this.game.world.centerY * 1.2, 'Instructions', () => {
      this.game.state.start('instructions');
    });

    let moveKeys = KEYS.filter((key) => key.indexOf('move') !== -1);
    let moveLabels = moveKeys.map((key) => keycode.names[keyConfig[key]].toUpperCase()).join(', ');
    this.makeText(this.game.world.centerY * 1.5, `${moveLabels} to move.`);

    let shootKeys = KEYS.filter((key) => key.indexOf('shoot') !== -1);
    let shootLabels = shootKeys.map((key) => keycode.names[keyConfig[key]].toUpperCase()).join(', ');
    this.makeText(this.game.world.centerY * 1.6, `${shootLabels} to shoot.`);

    this.makeText(this.game.world.centerY * 1.7, `${keycode.names[keyConfig.bomb].toUpperCase()} for bomb.`);


    this.pressSpace = this.makeText(this.game.world.centerY * 1.9, 'Press Space For New Game');

    tracking.mainMenu();
  }
github drhayes / blaster / src / states / options.js View on Github external
update() {
    super.update();
    if (this.listeningFor) {
      let button = this[this.listeningFor];
      let letter = Math.round(Math.random() * 25) + 65;
      button.buttonText.text = keycode.names[letter].toUpperCase();
    }
  }
github drhayes / blaster / src / states / mainMenu.js View on Github external
    let moveLabels = moveKeys.map((key) => keycode.names[keyConfig[key]].toUpperCase()).join(', ');
    this.makeText(this.game.world.centerY * 1.5, `${moveLabels} to move.`);

keycode

Convert between keyboard keycodes and keynames and vice versa.

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis