Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to input Chinese characters with SendKeys in VBS

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how VBS uses SendKeys to input Chinese characters". In daily operation, I believe many people have doubts about how VBS uses SendKeys to input Chinese characters. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how VBS uses SendKeys to input Chinese characters". Next, please follow the editor to study!

First, let's look at an example of entering letters:

The copy 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

This vbs SendKeys method friends will know that the function is to open a notepad, and then enter the "biweilun" string of characters, of course, you can change the code parameters to chr (97), then you will find that automatically entered into notepad is a "a" character. So, can you change the value of the code parameter to a chr (ASCII code of a Chinese character)? I can tell you for sure, no.

By calling an object of IE, we can use its built-in clipboard element to put the string "Bieweilun" into the clipboard, and then use the Wsh object to SendKey "^ v" to paste the clipboard contents, so that vbs can automatically enter Chinese characters.

However, the drawback of this method is that it opens an IE window, which is not perfect, although it does not affect the input characters. So I'm exploring a perfect solution to learn that an object "htmlfile" can only read the clipboard, but can't write it. Let's take a look at a piece of code, how to pop up the contents of your clipboard, you need to copy a character first:

Set biweilun=CreateObject ("htmlfile"). ParentWindow.clipboardData

WScript.Echo biweilun.GetData ("text")

Run this code and you will find that the contents of your clipboard pop up. In the IE object, there are SetData functions to write the clipboard, GetData functions to read the clipboard, and in the htmlfile object, there are also these two functions. Do you think that you can use the SetData of the htmlfile object to write Chinese characters to the clipboard first, and then SendKeys? This is not perfect, not only to solve the problem of Chinese input, but also no web page to pop up. Ha ha, the idea is good, I also thought so, but no!

Htmlfile object in use can only GetData to get the clipboard, for the SetData function system does not give it write permission! Ha ha, depressed, right? But the SetData function in the htmlfile object does exist, but it just doesn't work. If you don't believe it, you can try the following code yourself. The script will not report an error. Without this function, Wscript will report an error:

The copy code is as follows:

Set biweilun=CreateObject ("htmlfile"). ParentWindow.clipboardData

Biweilun.SetData "text", "Bieweilun"

WScript.Echo biweilun.GetData ("text")

In the space of vbs awesome UMU, according to him, there is a DOS command that can write a string to the clipboard:

Echo biweilun | clip.exe writes the character biweilun to the clipboard with the DOS command. After my test, the command is not valid. UMU's idea is to write the clipboard silently in the background:

ObjWSH.Run "cmd.exe / c echo" & szBuf & "| clip.exe", vbHide

If only this DOS command could be implemented, then the SendKeys Chinese characters would be perfect. I searched the Internet for a long time and couldn't find any information and parameters about what he called clip.exe.

Vbs uses SendKeys to input Chinese characters, but it's still a bit of a pity.

The supplementary content of 28 July is as follows:

After being mentioned by Brother UMU, it turns out that the clip.exe mentioned above is only available under Win2003, but WinXP is not available, so it's strange that I can't implement the DOS command for Windows to write clipboard in the background.

Now upload the Clip.exe in Win2003. Please download the clip.rar and unzip it, and copy the clip.exe to the% systemroot%\ system32 folder. Now the problem of vbs using SendKeys to input Chinese characters has been perfectly solved, as long as it is supported by clip.exe.

The code is as follows:

The copy 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

At this point, the study on "how VBS uses SendKeys to input Chinese characters" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report