检测浏览器是否在网页上的键盘/箭头键 [英] Detect whether browser has keyboard/arrow keys in web page

查看:274
本文介绍了检测浏览器是否在网页上的键盘/箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全屏幕游戏的HTML + JavaScript的,它使用箭头键为主要控制。这不能用在键盘的Andr​​oid设备(我还没有在iOS上测试),即使在软键盘有箭头键,将占用不必要的空间。因此,我增加了屏幕上的控制按钮。但是,按钮在桌面浏览器不必要的(和荒谬的大),所以我想,除非需要它们他们不会弹出。

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), and even if the soft keyboard had arrow keys it would take up unnecessary space. Therefore, I have added onscreen control buttons. However, the buttons are unnecessary (and absurdly large) on desktop browsers, so I would like them to not pop up unless they are needed.

我可以使用哪些启发,决定是否需要他们 - 也就是说,无论是不可能或难于使用输入方向键的事件 - 其他不承认具体的用户代理(其中很简单,但不是面向未来的)?

What heuristics can I use to decide whether they are needed — that is, whether it is impossible or awkward for the user to input arrow-key events — other than recognizing specific User-Agents (which is straightforward, but not future-proof)?

我当然会允许用户隐藏/显示按钮;我在寻找有用的启发式选择默认设置。

I will of course allow the user to hide/show the buttons; I am looking for useful heuristics for choosing the default setting.

推荐答案

无需任何用户代理嗅探,配置选项或任何形式的猜测。只要做到这一点:

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

  1. 有一个标题屏幕,说:preSS继续。
  2. 在单击或按键preSS,隐藏触摸控制,并开始游戏。
  3. 在触摸,显示触摸控制,并开始游戏。

您从来没有必要提选项的用户,并且自动检测他们的preferred控制完美。

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

这篇关于检测浏览器是否在网页上的键盘/箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆