Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Self-typing keyboard

  • Self-typing keyboard

    Posted by Graham Quince on August 14, 2021 at 9:51 am

    I’ve probably massively over-complicated this, but every so often I need an onscreen keyboard in my videos and in the past I’ve just assembled the visuals. As a day project, I decided to build a comp with essential graphics which I could drop in whenever I need it and use checkboxes to control the keypresses.

    During assembling this, I had the idea that maybe a cool feature would be to point it at a text layer and have it autotype the sentences. I’ve got most of it by adapting an expression Dan Ebberts helped me with previously, but I’m wondering if this is the most efficient way to go about it?

    And I tried adapting this for a second text layer, so the text would appear to type on corresponding to the key presses, but it appears the text does not have a persistance, each frame resets it. I know I could use the typewriter preset, i just thought it would be cute to link them.

    This is the expression I need to add to each keypress checkbox – it currently works only for the first letter, I’m trying to figure out why the next one doesn’t.

    state=0;

    thisKey = "h";

    textArray = effect("Text layer")("Layer").text.sourceText.toLowerCase().split("");

    keyDuration = effect("Key Down duration (frames)")("Slider")*thisComp.frameDuration;

    p = effect("Set keyframe for start")("Checkbox");

    if(p.numKeys > 0){

    n = p.nearestKey(time).index;

    if(p.key(n).time > time) {

    n--;

    }

    if(n > 0){

    t = p.key(n).time;

    if(time < t+keyDuration && textArray[Math.floor((time-t)/keyDuration)] == thisKey){

    state = 1;

    } else {

    state = 0;

    }

    }

    }

    state;

    I’m doing this for fun and will post the final project here too, in case anyone else wants it.

    Graham Quince replied 3 years, 8 months ago 2 Members · 4 Replies
  • 4 Replies
  • Graham Quince

    August 14, 2021 at 10:40 am

    For those interested, I’ve progressed my code:

    state=0;

    thisKey = "h";

    textArray = effect("Text layer")("Layer").text.sourceText.toLowerCase().split("");

    keyDuration = effect("Key Down duration (frames)")("Slider")*thisComp.frameDuration;

    p = effect("Set keyframe for start")("Checkbox");

    if(p.numKeys > 0){

    n = p.nearestKey(time).index;

    if(p.key(n).time > time) {

    n--;

    }

    if(n > 0){

    t = p.key(n).time;

    if (textArray[Math.floor((time-t)/keyDuration)] == thisKey){

    state = 1;

    } else {

    state = 0;

    }

    }

    }

    state;

  • Filip Vandueren

    August 17, 2021 at 10:09 pm

    So each key is on it’s own layer, and each layer has an opacity expression ?

    Looks like the keys are just hard on/off- ?

    In that case, I would make a sequence of 1 key at a time in a precomp and use timeremapping.

    Putting just the modifier-keys separately on their own layers, so they can light up together with other keys.

    A lot less expressions and a lot less layers.

  • Filip Vandueren

    August 18, 2021 at 12:41 pm

    Here’s my take on it:

    https://we.tl/t-sPECeVhHzn

  • Graham Quince

    August 21, 2021 at 10:46 am

    Oh wow – that’s so much more efficient!

    Anyone finding this thread, use Filip’s solution – not mine

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy