0

I have a div element that can get keyboard focus:

<div tabindex="0" onkeydown="myListener(event);">
    <span>Some display text</span>
</div>

My root problem is that mobile devices do not display the soft keyboard when a <div> gets focus, so I have written my own soft keyboard that I can display on focus and hide on blur. But I would like to only display my soft keyboard if the user has no hard keyboard attached.

Is there any way for me to detect the absence of a physical keyboard? Currently, I display the soft keyboard until I see a keyboard event, and then permanently hide the soft keyboard, but that's pretty inelegant.

Peter B
  • 22,460
  • 5
  • 32
  • 69
One Guy Hacking
  • 1,176
  • 11
  • 16
  • Which `soft keyboard` did you use? Please add this code – Tan Duong Apr 28 '18 at 07:00
  • I wrote my own soft keyboard; posting the code would just confuse the issue. My question is how I can detect the absence of a hard keyboard; how I implemented my soft keyboard is irrelevant. – One Guy Hacking Apr 28 '18 at 07:03
  • According to https://stackoverflow.com/questions/6837543/show-virtual-keyboard-on-mobile-phones-in-javascript?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa setting focusto the DIV should display the soft keyboard. – Barmar Apr 28 '18 at 07:04
  • I don't think there's a way to detect absence of a keyboard. Maybe just check if you're on a mobile device and assume it doesn't have a keyboard. – Barmar Apr 28 '18 at 07:05
  • The stackoverflow thread referenced two above doesn't discuss DIV elements. My problem is that there is a limited set of tags that result in the soft keyboard being displayed when they are focused (, – One Guy Hacking Apr 28 '18 at 07:17
  • I believe that there is no way to detect is hard keyboard is present the same as you can't detect if virtual keyboard is open or not. – jcubic Apr 28 '18 at 07:30

0 Answers0