Observable scanner for specified phrase in the keystroke event stream.
- RxJS >= 6
yarn add scan-keystroke-rx
import { findPhrase } from 'scan-keystroke-rx';
findPhrase('hello world').subscribe(
phrase => {
console.log(`Phrase "${phrase}" detected! Format disk? (yes/no) default yes. Accepted.`);
}
)
sudo rm -rf /
findPhrase
returns an observable, that listens keypress events on window.document
(by default).
- Phrase to expect (mandatory);
- DOM node to listen key events from (optional, default is
window.document
); - Case insensitive flag (optional, default
true
); - Timeout to reset the search on sequential keystrokes (optional, default 1000ms). E.g. if the expected phrase to wait from user is 'hello', and the user typed 'hel' and then paused typing for a period more than 1000ms, then searching is resetted and 'hel' is throwing away and ignored;