简体   繁体   English

检测手机物理按键按下(在javascript中)?

[英]detecting mobile phone physical button press (in javascript)?

I have a web site with four options. 我有一个带有四个选项的网站。 A friend mentioned that his old phone had no touch screen but did have a browser, and had a physical button on each of the four edges. 一位朋友提到他的旧手机没有触摸屏,但确实有一个浏览器,并且四个边缘各有一个物理按钮。

He asked, if I mapped the four keyboard arrows to the four website options, maybe his phone buttons would emulate them. 他问,如果我将四个键盘箭头映射到四个网站选项,也许他的手机按钮会模仿它们。 Is this crazy? 这疯了吗? Can this be done in javascript? 这可以在javascript中完成吗? I realize it depends on the phone, but are there general rules? 我意识到这取决于手机,但是有一般规则吗?

Rather than map the arrows and disabling the default behavior the user expects, you could try add the mobile access key at your anchors. 您可以尝试在锚点添加移动访问密钥,而不是映射箭头并禁用用户期望的默认行为。

Old phones with keyboard accept the attribute accesskey in anchors. 带键盘的旧手机接受锚点中的属性accesskey This way, if they press the keyboard number related, it will be the same effect as clicking in the link. 这样,如果他们按下相关的键盘编号,则与点击链接的效果相同。 You could try this but of course, will not work with devices with no keyboard (touch ones mostly). 您可以试试这个,但当然,不适用于没有键盘的设备(主要是触摸设备)。

Use is: <a href="some url" accesskey="1">My link</a> - The number in accesskey will be the number to be pressed on keyboard. 使用方法是: <a href="some url" accesskey="1">My link</a> -在数量accesskey将键盘上按下数字。

(PS.: Pending test on newer ones with keyboard to see if that tag is still supported). (PS:使用键盘对新版本进行待测测试,看看是否仍支持该标签)。

I think it highly unlikely to assume that a physical button press is the same as an arrow press. 我认为不太可能认为物理按钮按压与箭头按压相同。 Would a mousewheel be an arrow press, a spacebar, a touch and drag on a touch screen device? 鼠标滚轮是否会在触摸屏设备上按下箭头,空格键,触摸和拖动?

Best way to check is just to try. 最好的检查方法就是尝试。 Visit this site. 访问该网站。 Try some button presses. 尝试按一下按钮。 If they map to arrows then the displayed keycode will be 37, 38, 39 or 40 如果它们映射到箭头,则显示的键码将为37、38、39或40

http://jsfiddle.net/cwu4S/1/ http://jsfiddle.net/cwu4S/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM