In a recent project, I was responsible for the front-end of the web page. The customer needed to use a touch screen for operation without an external mouse and keyboard, but was required to be able to enter text, including numbers, English, and Chinese. After thinking about it, I decided to use JS to implement the virtual keyboard.
First of all, I searched for JS virtual keyboard on the Internet. After careful screening, I fell in love with VirtualKeyboard, a powerful JS virtual keyboard plug-in.
Let’s briefly introduce VirtualKeyboard. It has more than 100 built-in keyboard layouts, more than 200 input methods, 9 sets of optional skin plans, and supports self-built input methods. It is quite powerful.
Attach the download address first. The latest version is 3.94: http://www.corallosoftware.it/Download/download.html This tutorial uses 3.71 and does not provide a separate download. Friends who need it can download my modified version at the end of the article
After downloading, check out its demo document first, and then open Jsvkjscriptsdemo_inline.html. You can see that the virtual keyboard is quite beautiful and supports Chinese pinyin input, which is completely in line with expectations. As shown below:
Integrate it into the project and just do it!
First, copy the files in the Jsvkjscripts directory to the project. The text files and html demonstration files can be deleted.
JS files referenced in the project page:
vk_skin=flat_gray means flat_gray is selected as the default skin. These two can be set according to personal needs.
Function to call/hide virtual keyboard:
VirtualKeyboard.toggle("txt_Search", "softkey");
txt_Search is the ID of the text box, and softkey is the ID of the element where the virtual keyboard is displayed.
Here is a simple example:
Effect:
Customize the functions you need step by step
The basic functions have been implemented, and the next step is to switch between Chinese and English. First click CapsLock to switch to uppercase and try, but I was disappointed. When switching to uppercase in Chinese mode, the input is still Chinese. You can only click on the input method selection menu in the lower right corner, find US, and switch to the English input method. This is not possible. You have to switch back and forth among hundreds of options every time. What a poor user experience!
So, I had a preliminary idea, cleared the drop-down list, and manually built a list with only Chinese and English options. To clear the drop-down list, you must first know its ID. This kind of layer is usually created dynamically, so I found Jsvkjscriptsvirtualkeyboard.js and opened it. As expected, the code is compressed and can be read directly. God man. So we need to decompress it first. Open http://jsbeautifier.org/, copy the code in the JS file into the input box, click the button, and the decompression is complete. ctrl a, ctrl c to copy to the new JS file, OK, you can read it. Search for the "