To update the answer from Endy (in RxJS 7) (with sequenceEqual from rxjs sample, because, smart usage of it :D)
const table: {[key: string]: number} = {
ArrowUp: 38,
ArrowDown: 40,
ArrowLeft: 37,
ArrowRight: 39,
KeyB: 66,
// Azerty compat
KeyQ: 65,
KeyA: 65,
};
const knownSequence = from([38, 38, 40, 40, 37, 39, 37, 39, 66, 66]);
const konami$ = fromEvent<KeyboardEvent>(document, 'keyup').pipe(
map((e) => table[e.code] ? table[e.code] : -1),
skipWhile((k) => k !== 38),
bufferCount(10, 1),
mergeMap((x) => {
return from(x).pipe(sequenceEqual(knownSequence));
}),
filter((sequenceEqual) => sequenceEqual),
switchMap((_) => of('konami'))
);
// Basic usage (promisified)
await firstValueFrom(konami$);
// Do Konami thing