Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
}
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)
}
}
}
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;
}
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':
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)
}
it('exposes keycode/name maps', function() {
for (var code in keycode.codes) {
assert.strictEqual(keycode(code), keycode(keycode.names[keycode.codes[code]]))
}
})
let moveLabels = moveKeys.map((key) => keycode.names[keyConfig[key]].toUpperCase()).join(', ');
this.makeText(this.game.world.centerY * 0.6, `${moveLabels} to move.`);
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();
}
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();
}
}
let moveLabels = moveKeys.map((key) => keycode.names[keyConfig[key]].toUpperCase()).join(', ');
this.makeText(this.game.world.centerY * 1.5, `${moveLabels} to move.`);