Detect virtual keyboard vs. hardware keyboard

前端 未结 6 2097
心在旅途
心在旅途 2020-12-05 06:36

I have been thinking about this a while now, and I can\'t figure a way to deal with it. Is there any way to detect if the user uses a virtual (software) keyboard or a tradit

6条回答
  •  不知归路
    2020-12-05 07:29

    I came across a newer question the other day and a great answer that may help with your keyboard issue.

    Time out on jquery hover (touch)

    Essentially it uses a JQuery function that returns a boolean if it was able to create a touch event.

    $(document).ready(function() {
    
        function hasTouch() {
            try {
               document.createEvent("TouchEvent");
               return true;
            } catch (e) {
               return false;
            }    
        }
    
        var touchPresent = hasTouch();
    });
    

提交回复
热议问题