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 traditional (hardware) keyboard?
The new Windows Surface has its own keyboard in the cover, and for Android / iPad there are a ton of different bluetooth keyboards.
So, do any of you have any input about this?
I'm aiming for Android, IOS & Windows Tablet/Phone.
Motivation: (very subjective)
When developing web applications for tablet/smartphone I have come to the understanding that it's easier - in many situations - to use a JavaScript keyboard instead of the OS's software keyboard.
Lets say you want to enter a PIN code. Instead of having a keyboard filling half of the screen:
Software (OS) keyboard:
|----------------| | [ input] | | | |----------------| | 1 2 3 4 5 | | 6 7 8 9 0 | |----------------|
JavaScript keyboard:
|----------------| | [ input] | | | 1 2 3| | | | 4 5 6| | | |_7_8_9| | | | | | |----------------|
If you need to handle a lot of inputs, maybe you want to make an overlaying div
with the inputs and use the software keyboard:
|----------------| | P1 P2 P3 P4 | | [inp 1][inp 2] | |----------------| | KEYBOARD | | | |----------------|
But if the user has their own hardware keyboard, we want to make the edit inline in place.
I have been looking around SO and found this post: iPad Web App: Detect Virtual Keyboard Using JavaScript in Safari? ... but this seams to only work in IOS - not sure about browser.
A virtual keyboard is a software component that allows the input of characters without the need for physical keys. The interaction with the virtual keyboard happens mostly via a touchscreen interface, but can also take place in a different form in virtual or augmented reality.
Advantage of a Virtual Keyboard The Virtual Keyboard is designed to protect your password from malicious “Spyware” and “Trojan Programs”. Use of Virtual keyboard will reduce the risk of password theft.
Windows also has the On-Screen Keyboard (OSK), an Ease of Access tool. Use the OSK instead of a physical keyboard to move around your PC and enter text. You don't need a touchscreen to use the OSK. The OSK displays a visual keyboard with all the standard keys.
Approach: Unfortunately, currently there is no direct way to detect if a virtual keyboard appears on the screen using JavaScript. However, there are a few indirect ways using which we can detect when a virtual keyboard appears on the device’s screen. If a virtual keyboard appears on the screen, the height of the screen would be changed.
I personally find that typing on a virtual keyboard is much, much quicker than typing on a physical one. Why you ask? Though I can’t explain it with an exact science, I think most will agree it requires more force to push a physical button than the simple lite tap of a virtual one, thus allowing for a quicker typing experience.
Oxynger KeyShield have a lot potential to be one of the best if not the best security based virtual keyboards because it managed to protect against a low level keylogger but unfortunately it failed against “Any Keylogger”.
The effectiveness of screen logger protection in virtual keyboard software is very important, making Mouse Only Keyboard unsafe to use. The built-in On-Screen Keyboard in Windows is useless against keyloggers.
I think the best approach would be to combine HTML5 form attributes with an optional virtual keyboard link.
HTML5 form attributes can be used to trigger different types of keyboards. For example, <input type="email">
, <input type="number">
and <input type="tel">
will trigger the appropriate keyboard types on iOS (not sure about Android/WinPho/other, but I would imagine it does the same), allowing the user to input the data more easily.
If you want, you could additionally offer a button to trigger a custom numpad under the text field for older non-HTML5 compliant mobile browsers. Those will display the new HTML5 fields as standard text fields.
You can use browser sniffing to detect mobile browsers, but don't forget that those can still support things such as bluetooth keyboards. Sniffing additionally has the problem that it will almost certainly miss some browsers, and incorrectly detect others, thus you shouldn't rely on it solely.
I don't think overriding default onscreen keyboard is a good idea, and I'd recommend going with what Jani suggested - virtual keyboards adapt too.
But I'm sure it is possible to detect most keyboards with the resize
event paired with focus on the field or by monitoring window.innerHeight
(or some other [a-z]*Height) and comparing value before and after field focus.
This is a weird case of feature detection, so it will need plenty of experimentation. I wouldn't do it if I were you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With