Detect whether browser has keyboard/arrow keys in web page

前端 未结 8 953
忘了有多久
忘了有多久 2020-12-31 00:21

I have a full-screen game in HTML+JavaScript, which uses the arrow keys as primary controls. This cannot be used on keyboardless Android devices (I haven\'t tested on iOS),

8条回答
  •  抹茶落季
    2020-12-31 01:15

    No need for any user-agent sniffing, config options or any kind of guessing. Just do this:

    1. Have a title screen which says "press to continue".
    2. On click or key press, hide touch controls and start game.
    3. On touch, show touch controls and start game.

    You never even needed to mention the option to the user and you auto-detected their preferred control perfectly.

提交回复
热议问题