• Hi,
    im trying to send keyinputs using a PuckJS ( 2v19 (c) 2021 G.Williams).

    //http://www.espruino.com/BLE+Keyboard
    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    function btnPressed() {
      kb.tap(kb.KEY.A, kb.MODIFY.LEFT_GUI, kb.MODIFY.LEFT_ALT);
    }
    setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50});
    

    However, it throws this error, on every puck button press:

    BLE Connected, queueing BLE restart for later
    Uncaught Error: ERR 0x3401 (:3272)
    at line 1 col 104
    ...0,0,0],function(){a&&a()})})
    in function "tap" called from line 7 col 56
    kb.tap(kb.KEY.A, kb.MODIFY.LEFT_GUI, kb.MODIFY.LEFT_ALT);
    in function called from system

    Any ideas? Im using basically the same code as from the example and other forum threads e.g https://forum.espruino.com/conversations/371473/#comment16333536

    No idea why its not working.

  • It looks like error 0x3401 is BLE_ERROR_NOT_ENABLED (although I've never seen that reported before!).

    I think the issue is that you've enabled BLE HID with setServices, but then you're still connected by Bluetooth so the Puck can't restart the bluetooth stack to enable HID - hence the:

    BLE Connected, queueing BLE restart for later

    message...

    So all you need to do is upload your code, then disconnect and reconnect (which will allow the PC to detect that the Puck is now also a Bluetooth keyboard) and then everything should be fine

  • Im only connecting the Puck via Edge Browser to the Espruino IDE.

    Even after a power cycle, Windows 11 Bluetooth "Add Device" never finds the puckjs.

    Connection to the Web IDE via Web Bluetooth works almost instantly. However, it throws the above error everytime I press its button.

    --- When I save to flash, power cycle and reconnect to the Espruino IDE, the error looks slightly different (no BLE info)

    Uncaught Error: ERR 0x3401 (:3272)
     at line 3 col 275 in .bootcde
    ...0,0,0],function(){a&&a()})})
    in function "tap" called from line 8 col 58 in .bootcde
    kb.tap(kb.KEY.A, kb.MODIFY.LEFT_GUI, kb.MODIFY.LEFT_ALT);
    in function called from system
    

    1 Attachment

    • 2023-10-03_12-00.png
  • When I save to flash, power cycle and reconnect to the Espruino IDE

    Ok, so are you sure that after you've saved to flash, you then tried to connect with windows Add Device?

    Because if you saved to RAM and power cycled the Puck would have lost your code, so that's about what you'd expect.

  • 100sure that ive saved to flash -> ive looked into it via Espruino IDE after Power cycling.

    Ive also tried "Add Device" via Windows 11, the Puck just never shows up - it does show up in Chrome and Edge in the IDE though...

  • Just looking at the code again, and one thing that is an issue (but not the whole problem) is that you're calling tap slightly wrong:

    // kb.tap = function(keyCode, modifiers, callback)
      kb.tap(kb.KEY.A, kb.MODIFY.LEFT_GUI, kb.MODIFY.LEFT_ALT);
    

    So the third argument is expecting a function to call back but it's getting a variable - this is what you want I think:

    kb.tap(kb.KEY.A, kb.MODIFY.LEFT_GUI | kb.MODIFY.LEFT_ALT);
    

    But I just tried with a Puck here and the code appears to work. I've tested it on Android, iOS, Windows 10 and it all works...

    But I just tried Windows 11 and for some reason it doesn't show the device (Windows 10 shows loads of devices, but Windows 11 shows hardly any for me). I'll see if I can figure out what the problem is...

  • thanks a lot for your help!

    Im trying to get the combo: "WIN + ALT + B" send to Windows via Puck Keypress -> Switch HDR on and off.

    the above call of kb.tap() seems to work - https://forum.espruino.com/conversations/371473/#comment16333536

  • Ok, I've just managed to get this to appear in Windows 11 (by comparing with a Logitech device that does appear). It seems it needs an Appearance to be specified - which is something I'd never really come across before.

    Please can you add the following code - it'll alternate advertising between the normal advert and one that includes the appearance in it, which will get Windows 11 to list it:

    NRF.setAdvertising([
      {},
      [
        2, 1, 6,  // standard Bluetooth
        3,3,0x12,0x18, // HID Service
        3,0x19,0xc1,0x03 // Appearance: Keyboard https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Assigned_Numbers.pdf
      ]
    ]);
    

    I'll update the docs for this, and see if I can get support for it in the firmware too.

    As far as I know this must be some new addition to Windows 11 as I'm pretty sure it always used to work fine in Windows 11.

  • The puck now shows up immedieatly in Windows 11 "Add Devices" and connects as well.

    With this code, on button press, it just opens the quick settings window however 😅
    It seems to execute "Win + A", instead of "Win + ALT + A".

    However, huge thanks to your help already! No way, that I could have ever figured this out by myself.

    Espruino IDE still throws the same error as before though - even if it works in windows.


    1 Attachment

    • 2023-10-04_11-31.png
  • Did you definitely use the line I'd suggested instead of what you had:

    kb.tap(kb.KEY.A, kb.MODIFY.LEFT_GUI | kb.MODIFY.LEFT_ALT);
    

    Because with the previous code of kb.tap(kb.KEY.A, kb.MODIFY.LEFT_GUI, kb.MODIFY.LEFT_ALT);, "Win + A" is exactly what I'd expect

  • Yes, with your line nothing happens in Windows 11.

    How can I send a keypress combo with more than two inputs, if not via the above comma seperated "list".

    Nvm, im dumb - too early.

    function btnPressed() {
      kb.tap(kb.KEY.B, kb.MODIFY.LEFT_GUI | kb.MODIFY.LEFT_ALT);
    }
    

    of course you are correct. The above works fine. (Key.B instead of A) now switches Windows HDR Mode. Absolutely briliant. I love it.

    Thanks again! Your help has been absolutely amazing, I can now finally use my puck device! 😍

  • Ok, please can you try:

    NRF.sendHIDReport([kb.MODIFY.LEFT_GUI,0,0,0,0,0,0,0], function() {
      NRF.sendHIDReport([kb.MODIFY.LEFT_GUI | kb.MODIFY.LEFT_ALT,0,0,0,0,0,0,0], function() {
        NRF.sendHIDReport([kb.MODIFY.LEFT_GUI | kb.MODIFY.LEFT_ALT,0,kb.KEY.A,0,0,0,0,0], function() {
          NRF.sendHIDReport([0,0,0,0,0,0,0,0], function() {
          });
        });
      });
    });
    // or...
    NRF.sendHIDReport([kb.MODIFY.LEFT_GUI,0,0,0,0,0,0,0], function() {
      NRF.sendHIDReport([kb.MODIFY.LEFT_GUI,kb.MODIFY.LEFT_ALT,0,0,0,0,0,0], function() {
        NRF.sendHIDReport([kb.MODIFY.LEFT_GUI,kb.MODIFY.LEFT_ALT,kb.KEY.A,0,0,0,0,0], function() {
          NRF.sendHIDReport([0,0,0,0,0,0,0,0], function() {
          });
        });
      });
    });
    

    It's possible one of those will work?

  • Ahh - missed that - glad it worked!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Trying to send Key Inputs - Uncaught Error: ERR 0x3401 in function "tap"

Posted by Avatar for l00hn @l00hn

Actions