osric.uk

After testing, the code now looks like:

    async function* nextKey(target) {
        let q = Promise.withResolvers();

        function handler(e) {
            q.resolve(e);
        }

        target.addEventListener("keypress", handler);

        while (true) {
            yield await q.promise;
            q = Promise.withResolvers();
        }
    }

Promise.withResolvers returns an object with promise, reject, and resolve properties.

Next problem: keypress events don't capture tabs. ::SadFace::