First, let's look at an example of a letter:
Copy codeThe Code is as follows: set s = WScript. CreateObject ("WScript. Shell ")
App = s. Run ("C: \ windows \ notepad.exe ")
Code = "biweilun"
WScript. Sleep 1000
S. AppActivate app
S. SendKeys code
Wscript. quit
In this section, the vbs will know the SendKeys method. The function is to open a notepad and input the string "biweilun". Of course, you can replace the code parameter with chr (97 ), then you will find that the "a" character is automatically entered into the notepad. So, can't you change the value of the code parameter to a chr (ASCII code of a Chinese character) line? I can tell you for sure, no.
We call an IE Object so that we can use its built-in clipboard element to put the string "Bi weilun" into the clipboard, then, use the Wsh object to SendKey "^ v" to paste the clipboard content, so that vbs can automatically enter Chinese characters.
However, this method has a defect, that is, it will open an IE window, which is not perfect, although it does not affect the input characters. So I am exploring a perfect solution. I learned that an object "htmlfile" can only read the clipboard, but cannot write the clipboard. Let's take a look at a piece of code, how to pop up your clipboard content, you need to copy a paragraph of character first:
Set biweilun = CreateObject ("htmlfile"). parentWindow. clipboardData
WScript. Echo biweilun. GetData ("text ")
Run this code and you will find that your clipboard is popped up. In the IE Object, The SetData function is used to write the clipboard, and the GetData function is used to read the clipboard. In the htmlfile object, there are also two functions. Do you think that you can use the SetData of the htmlfile object to write Chinese characters to the clipboard and then SendKeys? This is not perfect. It not only solves the problem of Chinese input, but also does not display webpages. Oh, the idea is good. I thought so too, but no !!
In use, the htmlfile object can only GetData to obtain the clipboard, but the SetData function system does not grant it the write permission! Oh, depressed, right? However, the SetData function in the htmlfile object does exist, but it cannot be used. If you don't believe it, you can try the following code by yourself. The script will not report an error. If you don't have this function, Wscript will report an error:
Copy codeThe Code is as follows: Set biweilun = CreateObject ("htmlfile"). parentWindow. clipboardData
Biweilun. SetData "text", "Bi weilun"
WScript. Echo biweilun. GetData ("text ")
We can see from the space of the UMU in vbs that there is such a DOS command, which can be used to write strings to the clipboard:
Echo biweilun | clip.exe writes the string biweilun to the clipboard using the DOS command. According to my own test, this command is not valid. The UMU idea is to silently write the clipboard in the background:
Ob1_sh. Run "cmd.exe/c echo" & szBuf & "| clip.exe", vbHide
If this doscommand can be implemented, the SendKeys Chinese character will be perfect. I have been on the Internet for a long time, but I have not found any information about clip.exe and other relevant parameters.
Vbs uses SendKeys to input Chinese characters, which is a bit regrettable ~~~
The additional content for June July 28 is as follows:
After the upgrade of Umu, clip.exe, which was originally mentioned in the previous article, is available only under Win2003, and does not exist in WinXP. It is strange that I cannot implement the DOS command to write the clipboard in Windows in the background.
Upload clip.exein win2003to the file. Download clip.rar first and then decompress it. Copy the obtained clip.exe file to the % systemroot % \ system32 folder. Currently, vbsuses sendkeysto input the question of a Chinese character, which is supported by clip.exe.
The Code is as follows:Copy codeThe Code is as follows: Set wshobj = WScript. CreateObject ("WScript. Shell ")
Code = "the Chinese you want to enter"
Wshobj. Run "cmd.exe/c echo" & code & "| clip.exe", vbHide
App = wshobj. Run ("C: \ windows \ notepad2.exe ")
WScript. Sleep 1000
Wshobj. AppActivate app
Wshobj. SendKeys "^ v"
Wscript. Quit
The above code is perfect and effective after I test it ~~~