diff --git a/README.adoc b/README.adoc index dab7f19..0650a20 100644 --- a/README.adoc +++ b/README.adoc @@ -160,15 +160,15 @@ Iterates over the available link:plugins[], picks the compatible one for present [#generic] === `generic` -Emulates the end-user interaction by pressing the key with the specified `--key` option and iterates over the presentation as long as: +Emulates the end-user interaction by pressing the key with the specified `--key` option, and iterates over the presentation as long as: [loweralpha] -. Any change to the DOM is detected by observing mutation events targeting the body element and its subtree nor -. the number of slides exported has reached the specified `--max-slides` option. +. Any change to the DOM is detected by observing mutation events targeting the body element and its subtree, +. Nor the number of slides exported has reached the specified `--max-slides` option. -The `--key` value must be one of the {uri-w3c-uievents-key}[UI events `KeyboardEvent` key values] and defaults to `ArrowRight`, e.g.: +The `--key` option must be a list of {uri-w3c-uievents-key}[UI events `KeyboardEvent` key values], and defaults to `['ArrowRight']`, e.g.: - $ decktape generic --key=ArrowDown + $ decktape generic --key=ArrowDown --key=ArrowRight == Options diff --git a/plugins/generic.js b/plugins/generic.js index 5e2f196..77fa8c8 100644 --- a/plugins/generic.js +++ b/plugins/generic.js @@ -5,10 +5,12 @@ import { pause } from '../libs/util.js'; export const options = { - key : { - default : 'ArrowRight', + keys : { + full : 'key', metavar : '', - help : 'Key pressed to navigate to next slide', + list : true, + default : ['ArrowRight'], + help : 'Key pressed to navigate to next slide, can be repeated', }, maxSlides : { full : 'max-slides', @@ -24,12 +26,13 @@ export const options = { }; export const help = -`Emulates the end-user interaction by pressing the key with the specified --key option +`Emulates the end-user interaction by pressing the key with the specified --key option, and iterates over the presentation as long as: - Any change to the DOM is detected by observing mutation events targeting the body element and its subtree, - Nor the number of slides exported has reached the specified --max-slides option. - The --key option must be one of the 'KeyboardEvent' keys and defaults to [${options.key.default}].`; + +The --key option must be a list of 'KeyboardEvent' keys, and defaults to [${options.keys.default}].`; export const create = (page, opts) => new Generic(page, opts); @@ -39,7 +42,7 @@ class Generic { this.options = opts; this.currentSlide = 1; this.isNextSlideDetected = false; - this.key = this.options.key || options.key.default; + this.keys = this.options.keys || options.keys.default; this.media = this.options.media || options.media.default; } @@ -74,17 +77,22 @@ class Generic { if (this.options.maxSlides && this.currentSlide >= this.options.maxSlides) { return false; } - await this.page.keyboard.press(this.key); - // TODO: use mutation event directly instead of relying on a timeout - // TODO: detect cycle to avoid infinite navigation for frameworks - // that support loopable presentations like impress.js and flowtime.js - await pause(1000); - return this.isNextSlideDetected; + for (let key of this.keys) { + this.isNextSlideDetected = false; + await this.page.keyboard.press(key); + // TODO: use mutation event directly instead of relying on a timeout + // TODO: detect cycle to avoid infinite navigation for frameworks + // that support loopable presentations like impress.js and flowtime.js + await pause(1000); + if (this.isNextSlideDetected) { + return true; + } + } + return false; } nextSlide() { this.currentSlide++; - this.isNextSlideDetected = false; } async currentSlideIndex() {