問題描述
使用 javascript 檢測硬件鍵盤存在的最佳跨瀏覽器和跨平臺方法是什么?
What is the best cross-browser and cross-platform way to detect hardware keyboard presence with javascript?
推薦答案
這可能是一個老問題,但幾個月前,我自己也在尋找解決方案.我正在構建一個消息傳遞系統,當有人在物理鍵盤上點擊 Return
時應該發送消息,但當有人在虛擬鍵盤上點擊 Return
時插入換行符.我解決它的方法是計算 keydown
和 keyup
事件之間的時間,并在 Return
被擊中時獲取平均值.
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.
這篇關于如何使用 javascript 檢測硬件鍵盤的存在?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!