• Hello all! I'm new here and I was hoping to get help with my new device. I just picked up my Puck.Js and trying to turn it into a remote PTT button for Discord. I currently use CAPSLOCK as my PTT and struggling with getting it to work. It looks like it only very momentarily presses the key and doesn't hold it down while I'm holding the Puck.js button down. Could anyone let me know whats going on with my code?

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    function btnPressed() {
      var pressKey = true;
    
      setTimeout(function() {
        pressKey = false;
      }, 1000);
    
      // Send 'CAPSLOCK'
      while (pressKey) {
        kb.tap(kb.KEY.CAPS_LOCK, 0);
      }
    }
    
    // trigger btnPressed whenever the button is pressed
    setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50})­;
    

    Thank you all!

  • My friend ended up helping me out. Heres the code I got to work. Posting it here for anyone who needs it.

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    function btnPressed() {
      // Send 'CAPSLOCK'
      NRF.sendHIDReport([0, 0, kb.KEY.CAPS_LOCK, 0, 0, 0, 0, 0]);
    }
    
    function btnDepressed() {
      // Send 'None'
      NRF.sendHIDReport([0, 0, 0, 0, 0, 0, 0, 0]);
    }
    
    // trigger btnPressed whenever the button is pressed
    setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50})­;
    // trigger btnDepressed whenever the button is released
    setWatch(btnDepressed, BTN, {edge:"falling",repeat:true,debounce:50}­);
    
  • That code looks great - thanks for the update!

    But yes, tap just 'tap's the key, so you have to send the command manually like you did

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

Trying to set Puck.Js as a Push-to-talk button in Discord.

Posted by Avatar for user155924 @user155924

Actions