You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Formatting of code inside Html form TextArea element can be a bit tricky for the browser parser. There have been a few hiccups I've seen.

    @Robin can you point to one? Every issue I've seen thus far (apart from hashes inside code) has been an issue with the formatting of the text the post. If you haven't used it before it can take a while to get the hang of.

    I just checked this post, and there are three backticks before your code, but not after it as well (I guess you might have pasted over them by accident?). I just edited it to add them and it's fine now.

    Anyway - back to the question :)

    What you're doing in sendCap with the nesting looks fine to me. I'll check it out here and get back to you - it's possible you need a delay as the host computer may not be expecting to be getting keypresses sent so quickly.

    But the other main issue you have (why sendNewTest doesn't work) is:

    Why is it that the tap() has to be nested like that?

    This is an issue if you're new to JavaScript. Basically it can take a while to send a keypress (if you're in a low power mode it might be half a second). Rather than stop you running any other code during that time, Espruino executes the function right away and goes on to execute what's right after. When the keypress is finally sent, it calls the callback function - and it's in that function that you need to send the next keypress - hence the nesting.

    There are ways to get around that - for instance calling the same function over and over, taking characters off a string of characters to send - or you can use 'Promises' (a standard JS thing - google it for some good tutorials) to avoid the nesting as well.

About

Avatar for Gordon @Gordon started