Created
April 23, 2020 01:43
-
-
Save DanEdens/a6fba7d33c2f85bfd73bcab42e30d6bc to your computer and use it in GitHub Desktop.
Keypresses_puppeteer.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.stdin.on('keypress', async (str, key) => { | |
if (key.sequence === '\u0003') { | |
await browser.close(); | |
process.exit(); | |
} | |
if (['up', 'down', 'left', 'right', 'enter'].includes(key.name)) { | |
const capitalized = key.name[0].toUpperCase() + key.name.slice(1); | |
const keyName = `Arrow${capitalized}`; | |
console.log(`page.keyboard.down('${keyName}')`); | |
await page.keyboard.down(keyName); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment