VBS uses SendKeys to enter Chinese characters _vbs

Source: Internet
Author: User
Tags chr
First we look at an example of an input letter:
Copy Code code 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

This VBS will SendKeys method friends know, the role is to open a notepad, and then "Biweilun" this string of characters into, of course, you can replace the code parameter CHR (97), then you will find that automatically entered into Notepad is a "a" character. So, are you going to replace the value of the code parameter with a CHR (ASCII code for a Chinese character)? I can tell you for sure, No.

By calling an IE object, we can use its built-in clipboard elements, put "Bi Weilen" This string into the Clipboard, and then wsh the object to Sendkey "^v" paste the contents of the Clipboard, so that the VBS can automatically enter the Chinese characters.

However, this method has a drawback, that it will open an IE window, not perfect, although not affect the input characters. So I'm exploring a perfect solution to knowing that an object is "Htmlfile", but unfortunately the object can only read the Clipboard, but not the Clipboard. Let's look at a piece of code, how to eject your clipboard content, you want to copy a character first:

Set biweilun=createobject ("Htmlfile"). Parentwindow.clipboarddata
WScript.Echo Biweilun. GetData ("text")

Run this code and you'll find your clipboard stuff bouncing out. In IE objects, there are setdata functions to write the Clipboard, GetData function to read the Clipboard, in the Htmlfile object, there are these two functions. Do you think you can use the SetData of the Htmlfile object to write Chinese characters to the Clipboard before you SendKeys? This is not perfect, not only solve the problem of Chinese input, and no Web pop-up. Oh, the idea is good, I also think so, but not!!
The Htmlfile object can only be getdata to get the Clipboard in use, and the SetData function system does not write permissions to it! Oh, depressed it? But the SetData function in the Htmlfile object does exist, but it just can't be used. Do not believe the reader can try the following code, the script will not complain, if there is no this function, WScript will be the error:

Copy Code code as follows:

Set biweilun=createobject ("Htmlfile"). Parentwindow.clipboarddata
Biweilun. SetData "text", "Bi Weilen"
WScript.Echo Biweilun. GetData ("text")



In the Umu space of the VBS cow, he says there is a DOS command that can be used to write a string to the Clipboard:

Echo biweilun| Clip.exe is to use the DOS command to write Biweilun this string of characters to the Clipboard. After I test, the command does not set up, Umu's idea is to silently write the Clipboard backstage:

Objwsh.run "cmd.exe/c echo" & Szbuf & "| Clip.exe ", vbhide
If this DOS command can really be implemented, then the SendKeys Chinese character will be perfect. I went online for a long time and didn't find anything about his so-called clip.exe data and parameters and so on.

VBS using SENDKEYS input Chinese characters, there is a little regret ~ ~ ~ ~
The supplementary content of July 28 is as follows:

After Umu eldest brother's point, the original mentioned above Clip.exe only under Win2003 only, WinXP is not, that blame I can't implement the DOS command for the background Windows write clipboard

Now will Win2003 in the Clip.exe upload, please download Clip.rar first download After the decompression, the resulting clip.exe copied to the%SystemRoot%\System32 folder below. Now VBS with SendKeys input in the text of the problem can be perfectly solved, the premise is Clip.exe support.

The code is as follows:
Copy Code code as follows:

Set wshobj=wscript.createobject ("Wscript.Shell")
Code= "You want to enter the Chinese"
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 by my test perfectly effective, knot paste ~ ~ ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.