简体   繁体   中英

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? 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. 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.

(PS.: Pending test on newer ones with keyboard to see if that tag is still supported).

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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