How do I detect hardware keyboard presence with javascript?

后端 未结 5 1947
攒了一身酷
攒了一身酷 2020-12-17 10:30

What is the best cross-browser and cross-platform way to detect hardware keyboard presence with javascript?

5条回答
  •  粉色の甜心
    2020-12-17 11:19

    This may be an old question, but a few months ago, I was looking for a solution to this myself. I was building a messaging system which should send the message when someone hits Return on their physical keyboard, but inserts a newline when someone hits Return on a virtual keyboard. The way I solved it was by counting the time between keydown and keyup events and getting the average when Return was hit.

    I finally got around to documenting it on my blog here.

提交回复
热议问题