import {Observable} from 'rx';
import keycode from 'keycode';

export function makeKeysDriver () {
  return function keysDriver() {
    return {
      presses (key) {
        let keypress$ = Observable.fromEvent(document.body, 'keypress');

        if (key) {
          const code = keycode(key);

          keypress$ = keypress$.filter(event => event.keyCode === code);
        }

        return keypress$;
      }
    }
  }
}

import {Observable} from 'rx';
import keycode from 'keycode';

export function makeKeysDriver () {
  return function keysDriver() {
    const methods = {};
    const events = ['keypress', 'keyup', 'keydown'];

    events.forEach(event => {
      const methodName = event.replace('key', '');

      methods[methodName] = (key) => {
        let event$ = Observable.fromEvent(document.body, event);

        if (key) {
          const code = keycode(key);

          event$ = event$.filter(event => event.keyCode === code);
        }

        return event$;
      }
    });

    return methods;
  }
}

Add new methods to support keyup and keydown events
Add new methods to support keyup and keydown events
