• I'm setting up a Puck to work with my iPhone as a BLE keyboard, all good so far but iOS has an annoying habit that it disables the on screen keyboard if there's a hardware one connected.
    You can toggle the on-screen keyboard using the eject key on Apple Keyboards, which I belive is keycode 0x92.

    I'd like to be able to send this from my puck so I don't have to keep disconnecting the keyboard in bluetooth each time.

    Any ideas how to do this? I've tried

    NRF.sendHIDReport([0,0,146,0,0,0,0,0]
    

    and

    NRF.sendHIDReport([0,0,0x92,0,0,0,0,0]
    

    without any luck

  • That's odd - You do have to send the 'keyup' event as well, so:

    NRF.sendHIDReport([0,0,0x92,0,0,0,0,0]);­
    setTimeout(function() {
      NRF.sendHIDReport([0,0,0,0,0,0,0,0]);
    }, 100);
    

    Might do it?

    However, in the 'HID Report' you have to give a 'logical maximum', which is the maximum keycode value you intend to send. In http://www.espruino.com/modules/ble_hid_­keyboard.js you can see 0x25, 0x73, // Logical Maximum (115 - include F13, etc) and again a few lines later

    So if the above doesn't work, you could try copying the hid_keyboard code into your project, and changing 0x25, 0x73, to 0x25, 0x93, (as well as the line below)

  • Hi Gordon,

    Sorry yes should have said I was doing the key up event as well just posted the keycode bit for clarity

    Thats a good point about the maxium I'll try that, do I need to raise both Logical Maxiumum and Usage Maximum ?

    Also I was confused about the vaule of the Keycodes are they Hex or Dec? the library seems to have hex for the modifiers and dec for the keycodes? are they just interchangable

  • no joy with sending it as a keycode or a modifier, built a little app that just steped through each code to see what would happen!

    With a little more digging it seems like the way to toggle it is to send AL Keybard Layout as one of the Application Launch Buttons on the USB HID spec, (section 15)

    I found this SO post https://stackoverflow.com/questions/2218­1883/bluetooth-le-hid-eject-key-code which looks like they're creating a second report object with the Application Launch buttons and then sending that for the toggle, but I couldn't figure out how to translate that into espruino to send the alternate report in NRF.sendHIDReport, is there a way to select the report ID?

  • SUCCESS!
    After a bit more experimenting (aka brute forcing) I managed to figure out how to call the 2nd report. This code will add the ability to toggle the on screen keyboard in iOS devices when connected to a BLE keyboard from espruino.
    We extend the built in keyboards report with the additional codes and then set that wiht servies so you can still use all the existing features of ble_hid_keyboard like kb.tap(kb.KEY.A, 0);

    I've tested this on a pixl.js running 2.09 against an iPhone running iOs 14.6 so it works until Apple decide to change something!

    var kb = require("ble_hid_keyboard");
    
    togleReport = new Uint8Array([
    // 2nd Report for iOS Toggle Keyboard  
      0x05, 0x0C,                     // Usage Page (Consumer)
      0x09, 0x01,                     // Usage (Consumer Control)
      0xA1, 0x01,                     // Collection (Application)
      0x85, 0x02,                     //     Report Id (2)
      0x15, 0x00,                     //     Logical minimum (0)
      0x25, 0x01,                     //     Logical maximum (1)
      0x75, 0x01,                     //     Report Size (1)
      0x95, 0x01,                     //     Report Count (1)
    
      0x0A, 0xAE, 0x01,               //     Usage (AL Keyboard Layout)
      0x81, 0x06,                     //     Input (Data,Value,Relative,Bit Field)
      0xC0                            // End Collection
    ]);
    //Append the new report to the built in kb report
    var report = new Uint8Array(kb.report.length + togleReport.length);
    report.set(kb.report);
    report.set(togleReport, kb.report.length);
    
    //Set services with new combined report
    NRF.setServices(undefined, { hid : report });
    
    //Call this function to toggle the on screen keyboard
    function toggleKB(){
      NRF.sendHIDReport([2,1], function() {
        NRF.sendHIDReport([2,0], function() {}); 
      });
    }
    
    
    
    
  • That's awesome - thanks! And thanks for posting the code - are you ok with me sticking that on the BLE Keyboard page? Seems like it'd be pretty useful!

  • Sure, I updated the title to try and make it easier to find but putting it on the docs page seems like a good idea,
    There's probabbly a few more of these AL keys that could do interesting things with iOS, I also found that sending keyboard modfier 17 toggles the voice input keyboard.

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

Toggle iOS on-screen keyboard with BLE HID Keyboard connnected - SOLVED!

Posted by Avatar for sammachin @sammachin

Actions