You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • @tronic98776,

    sorry for being a bit short: s parameter is the string (of characters) you want to send.

    For example, if you want to send ABC you say hidKBD.type("ABC");. (...EDITED)

    
    Assuming it is the very first time just after uploading the code and nothing has been sent yet, no sending is going on, and therefore ```hidKBD.string``` is empty.  ```ABC``` shows up for sending, and because ```hidKBD.string``` is empty, we have to get the sending of character by character has to be started. We have two options to do it:
    
    - 1. set a boolean state for empty, then add the string, and then depending of the stored state of empty start the process:
    
    

    , type: function(s) { // feeding the FIFO w/ s(tring) to write

    var empty = (this.string.length === 0); // if string is empty (no sending is going on (anymore))
    this.string += s; // add string to FIFO w/ simple concat
    if (empty) { // 'was' empty, so sending has to be started, otherwise not
    

    ```

    • 2. add the string, then check if the total string length is the same as the added string, which means - retrospectively - that string was empty before we added the string.... this is all there is to this.

    Imagine you have to feed a plant with a constant low flow of water. You could baby sit this 24 x 7, 365... or, you place a bucket with a small whole in it that just meets your low flow requirement. Then - once in a while - you fill that bucket with another one by filling this other bucket from a pond by submersion and pour all into the first bucket with one big pour. If no water was left in the bucket, water starts to flow. If there was still water in it, flow continued with just a refilled bucket.

About

Avatar for allObjects @allObjects started