dmamontov / esphome-blekeyboard

ESPHome BLE Keyboard
https://community.home-assistant.io/t/esphome-ble-keyboard/
84 stars 16 forks source link

Press and hold down key #18

Open gitolicious opened 1 year ago

gitolicious commented 1 year ago

Describe the bug How can I press and hold a key? For example I would like to hold down the space bar for five seconds. Would have expected this to work:

button:
  - platform: template
    name: "Hold Space"
    id: hold_space
    on_press:
      then:
      - ble_keyboard.press:
          id: myblekeyboard
          code: 0x20 # space
      - delay: 5000ms
      - ble_keyboard.release: myblekeyboard

It results in just the space bar being sent and immediately relesed. Did I misunderstand the press function in that it doesn't hold down the key until release is called? When would you use the release function otherwise?

Please complete the following information:

dmamontov commented 1 year ago

@gitolicious In your case, a combination should help:

button:
  - platform: template
    name: "Hold Space"
    id: hold_space
    on_press:
      then:
      - ble_keyboard.combination:
         id: myblekeyboard
         delay: 5
         keys:
           - 0x20
           - 0x20
gitolicious commented 1 year ago

I guess for that exact use case it would actually work - at least I can see a lot of space key events when putting 1000 instead of 5) I don't fully understand why this works with space (0x20) but not with "o" where two individual letters are being printed. Unfortunately there are two extensions I would need for my actual use case: