Keyboard shortcut on press

Posted on
  • I'm a complete newbie but I know the Puck 2 is the thing for the job for me here...!

    I want to use it to perform a keyboard shortcut on press.

    When the button is pressed, I want it to perform Ctrl+Shift+M and then flash the red LED continuously until the button is pressed a second time. On the second press I want it to perform the same keyboard shortcut again and turn the LED off.

    I have had a look at a few support articles about doing a keyboard sequence which I have copied in and that is working to make it type 'Hello' but my request is slightly different as I think it needs to do the key press simultaneously rather than one after the other and also needs to check whether the LED is already flashing to figure out whether it needs to start or stop flashing.

    Any help is much appreciated and happy to pay for someone's time to code it if that is an option!

    All the best

    Toby

  • You are using HID to send the key sequence I suppose? You could post the code you have so far so we can better see what you're working with.

    I don't own a Puck, but if it's the same or similar functions than on the Bangle, you can add a "modifier" key to the HID report that is sent, i.e. instead of just sending "m" you can send "LCtrl+LShift+m" for example. See for some details here. The values for the modifiers are actually bits that you can add up, so to use LCtrl+LShift you would use 3 in the modifier field. Don't forget to send another report with all 0's to release the keys again.

    For the LED you would simply want to create a variable that tracks the LED's state, i.e. switch it to 1 when you switch the LED on and vice versa.

    Hope that helps.

  • Hi! As @Sebastian pointed out you should almost be able to do what you want with:

    https://www.espruino.com/BLE+Keyboard

    So something like this:

    var flashing = false;
    
    function btnPressed() {
     if (flashing) {
       flashing = false;
      // stop flashing the LED here
     } else {
       flashing = true;
       // start flashing the LED here
       kb.tap(kb.KEY.M,  kb.MODIFY.SHIFT |  kb.MODIFY.CTRL, function() {
      });
     }
    }
    
    // trigger btnPressed whenever the button is pressed
    setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50});
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Keyboard shortcut on press

Posted by Avatar for saibot @saibot

Actions