Skip to content

Instantly share code, notes, and snippets.

@suchipi
Created January 23, 2022 04:00
Show Gist options
  • Save suchipi/46dd77c1ad2c6f9d8fffd86d55abe7a0 to your computer and use it in GitHub Desktop.
Save suchipi/46dd77c1ad2c6f9d8fffd86d55abe7a0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env suchibot
import { Keyboard, Key, record, Tape, isMouseEvent } from "suchibot";
let tape: Tape | null = null;
Keyboard.onUp(Key.SCROLL_LOCK, () => {
if (tape && tape.isRecording) {
tape.stop();
console.log("Stopped recording");
} else {
if (tape) tape.stop();
tape = record({
eventFilter: (event) => {
if (isMouseEvent(event)) return true;
return !(
event.key === Key.SCROLL_LOCK || event.key === Key.PAUSE_BREAK
);
},
});
console.log("Recording to tape...");
}
});
Keyboard.onUp(Key.PAUSE_BREAK, async () => {
if (!tape) return;
console.log("Replaying tape...");
await tape.play();
console.log("Tape playback finished");
});
console.log("Recording system ready. Controls:");
console.log(" Scroll Lock: Start/stop recording");
console.log(" Pause/break: Replay recording");
@suchipi
Copy link
Author

suchipi commented Jan 23, 2022

0.5.0 version:

#!/usr/bin/env suchibot
import { Keyboard, Key, Tape, keyboardEventFilter } from "./index";

const tape = new Tape([
  keyboardEventFilter({ key: Key.SCROLL_LOCK }),
  keyboardEventFilter({ key: Key.PAUSE_BREAK }),
]);

Keyboard.onUp(Key.SCROLL_LOCK, () => {
  switch (tape.state) {
    case Tape.State.IDLE: {
      console.log("Recording...");
      tape.record();
      break;
    }
    case Tape.State.RECORDING: {
      console.log("Recording stopped...");
      tape.stopRecording();
      break;
    }
  }
});

Keyboard.onUp(Key.PAUSE_BREAK, async () => {
  switch (tape.state) {
    case Tape.State.IDLE: {
      console.log("Playing...");
      await tape.play();
      console.log("Playback finished");
      break;
    }
    case Tape.State.PLAYING: {
      console.log("Stopping playback...");
      tape.stopPlaying();
      break;
    }
  }
});

console.log("Recording system ready. Controls:");
console.log("  Scroll Lock: Start/stop recording");
console.log("  Pause/break: Replay recording");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment