Skip to content

Instantly share code, notes, and snippets.

@alaingalvan
Created August 14, 2019 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaingalvan/e8e8720f86b0de2bf19db850c0e8bc6e to your computer and use it in GitHub Desktop.
Save alaingalvan/e8e8720f86b0de2bf19db850c0e8bc6e to your computer and use it in GitHub Desktop.
Recording VS Code for use in YouTube Videos, etc.

So I wanted to make an animation of code being written in the minimap, so I set up VS Code so that it would write the minimap canvas to a PNG file every time there's a backspace (play that in reverse and you have typing out a file).

var fs = require('fs')
var curFrame = 0;
function saveCallback() {
    // Get the DataUrl from the Canvas
    const url = document.querySelectorAll('canvas')[1].toDataURL();

    // remove Base64 stuff from the Image
    const base64Data = url.replace(/^data:image\/png;base64,/, "");
    fs.writeFile('E:/Desktop/codeframes/'+curFrame + '.png', base64Data, 'base64', function (err) {
        console.log(err);
    });
    curFrame++;
}
let backspaceCallback = (e) => {
    /*
     * keyCode: 8
     * keyIdentifier: "U+0008"
    */
    if(e.keyCode === 8 && document.activeElement !== 'text') {
        e.preventDefault();
        console.log('backspace ' + curFrame);
        saveCallback();
    }
};
window.addEventListener("keydown", backspaceCallback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment