WScript Sendkey doesn't accept Unicode Characters

南笙酒味 提交于 2019-12-11 03:28:31

问题


I am trying to send char "ä" using WScript Sendkeys.Seems its not working . I found one post Does or Can VBscript's SendKeys support Unicode?

My Code:

Set sh = WScript.CreateObject("WScript.Shell")
sh.Run "notepad.exe", 9
WScript.Sleep 1000 'wait a while to load notepad app'
sh.SendKeys " äää Hello World!"  //buggy line
sh.SendKeys "{ENTER}"
WScript.Sleep 100'
sh.SendKeys "^p"

but i am unable to understand the solution. Would be great if you teach me in plain simple code (for solution). I am not good at WScript(as its not my area). I know i am begging for code(Pz forgive me). but plz understand my situation.

Many thanks in advance!!


回答1:


Windows Script Host's SendKeys doesn't support Unicode.

Alternatives to WSH/SendKeys:

  • Use the free tool AutoIt for GUI automation. You can use AutoIt's Send, ControlSend or ControlSetText commands to automate text input.

    Run('notepad.exe')
    WinWaitActive("[CLASS:Notepad]", "", 10)
    ControlSend("[CLASS:Notepad]", "", "Edit1", "äää Hello World!")
    
  • Write code in another programming language (C++, C# etc) and call the Windows API SendInput function with the KEYEVENTF_UNICODE flag.




回答2:


The comment is wrong. There is no such thing as a unicode, or any other code, keyboard except for keyboard codes called scancodes. If you can't enter it at the keyboard then neither can sendkeys. They are keystrokes not characters. The meaning depends on the keyboard layout you are using. Use the same keystrokes as the keyboard. Windows converts it into a ascii character if the Window was created with CreateWindowA or a unicode character if the window was created with CreateWindowW.



来源:https://stackoverflow.com/questions/23058634/wscript-sendkey-doesnt-accept-unicode-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!