• Hi there !

    A little update on the topic: I now have a working implementation of a modified version of USBKeyboard.js ( modified to handle FR layout & "high-type" feature* )

    https://github.com/stephaneAG/serialToWebsockets/blob/master/USBKeyboard2.js

    It could be used as a drop-in replacement for USBKeyboard module, and while it's a little bit bigger, it's quite nice to use ( at least to my taste ;p )

    *the main goal, aside from having a layout that maps to my keyboard key mapping, is to be able to 'type' stuff while not taking care of which modifier flag(s) have to be set for some specific character: just '.htype()' & this 'll be handled internally :D

    usage examples:

    var kb = require("USBKeyboard2");
    // use as the original USBKeyboard module
    setWatch(function() {
      kb.setModifiers(kb.MODIFY.SHIFT, function() {
        kb.type("HELLO WORLD", function() {
          kb.setModifiers(0, function() {
            kb.tap(kb.KEY.ENTER);
          });
        });
      });
    }, BTN, {debounce:100,repeat:true, edge:"rising"});
    
    // enjoy niceties
    exports.htype('abcdefghijklmnopqrstuvwxyz');
    exports.htype('abcdefghijklmnopqrstuvwxyz'.toUpperCase());
    exports.htype('aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
    exports.htype('1234567890');
    
    // combine with .tap() .. and do inception ? ^^
    exports.htype('exports.htype("lol");', function(){ exports.tap(KEY.ENTER); });
    
    // combine any char & it will auto handle applying the right modifier flag(s)
    exports.htype('rgb(0, 255, 128)');
    exports.htype('#0FAC3A');
    exports.htype('hsl(360, 100%, 50%)');
    
    // not all characters are supported this way, but adding them is quite easy ( ex: for "©" )
    exports.htype('Hello World Espruino© USBKeyboard2.js module !');
    

    Support for accents & additional characters is to be added in a near future ;)

    Side note: it seems the ™ character isn't supported in the Espruino IDE ? ( it prints "?", which isn't the mapped key ? .. )

    Now onto testing "mixed" device ( appearing as a keyboard + mouse combo ) on it & then on puckjs, I hope this 'll be helpful to some folks out there ;P
    +

About

Avatar for stephaneAG @stephaneAG started