The Konami Code (Japanese: コナミコマンド, Konami Komando, "Konami command"), also commonly referred to as the Contra Code and sometimes the 30 Lives code, is a cheat code that appears in many Konami video games, as well as some non-Konami games. In the original code, the player has to press the following sequence of buttons on the game controller to enable a cheat or other effects:
↑ ↑ ↓ ↓ ← → ← → B A
; sometimes Start and/or Select is added to the sequence (usually to start Single player or, Two player modes). ~Konami Code | Wikipedia
- About
- Installation
- Options
- Example
- Requirements
- Supported Browsers
- @shgysk8zer0/konami on npm
- @shgysk8zer0/konami on unpkg
- Issues
- Contributing
- Changelog
konami.js
enables developers to easily add the Konami Code to their websites.
Like other JavaScript solutions, this one adds keyboard listeners and waits
for the specifc sequence of keys to be pressed. Unlike other solutions, however,
this one:
- Is a JavaScript module
that may be
import
ed - Returns a
Promise
that resolves when the correct sequence is entered and may beawait
ed - Supports
AbortSignal
- Allows specifying the
EventTarget
via the optional{ target }
.
npm i @shgysk8zer0/konami
git submodule add https://github.com/shgysk8zer0/konami.git js/konami
const { konami } = await import('https://unpkg.com/@shgysk8zer0/konami');
git submodule update --remote -- js/konami
Tip: Use Dependabot to automatically get Pull Requests when a submodule or package is updated.
import { konami } from '/js/konami/konami.js';
await konami({ target, delay, signal, capture });
Name | Type | Default Value | Description |
---|---|---|---|
target |
EventTarget |
globalThis |
Target to listen for input on |
delay |
Number |
1000 |
Allowed delay in ms between inputs |
signal |
AbortSignal |
undefined |
See signal on MDN |
capture |
Boolean |
true |
See capture on MDN |
import { konami } from '/js/konami/konami.js';
konami().then(/* Enter Cheat Mode! */);
import { konami } from '@shgysk8zer0/konami';
// or const { konami } = require('@shgysk8zer0/konami');
konami().then(/* Enter Cheat Mode! */);
const controller = new AbortController();
// This will use version 1.0.5
const { konami } = await import('https://unpkg.com/@shgysk8zer0/[email protected]/konami.js');
try {
await konami({
delay: 500,
target: document.getElementById('konami-target'),
signal: controller.signal,
capture: true,
});
/* Enter Cheat Mode! */
} catch(err) {
// Signal was aborted
}
Due to use of signal
, support is currently limited to browsers supporting
AbortSignal
& AbortController
. Support may be extended to other browser by
importing a polyfill.
Browser | Supported | Version | Released |
---|---|---|---|
Internet Explorer | 𐄂 | ||
Edge | ✓ | 16 | 2017-10-16 |
Safari | ✓ | 12.1 | 2019-03-24 |
Chrome | ✓ | 66 | 2018-04-16 |
Firefox | ✓ | 57 | 2017-11-13 |
Node | ✓ | 15 | ? |
Deno | ✓ | 1.0 | ? |