Does or Can VBscript's SendKeys support Unicode?

限于喜欢 提交于 2019-12-01 20:37:50
Helen

You're most likely right in your guess that VBscript's SendKeys doesn't support Unicode.


Monitoring of Windows API function calls performed by SendKeys (using API Monitor and Blade API Monitor on Russian Windows XP with English US, Russian and Hebrew keyboards) shows that SendKeys isn't Unicode aware. Specifically, SendKeys does the following:

  1. Calls the ANSI (not Unicode) version of the VkKeyScan function — VkKeyScanA — to get the virtual key code of the character to be sent. This function translates the character into VK_SHIFT + VK_OEM_2, so it seems that somewhere before or in the process the Aleph character is converted into a different, ANSI character.

  2. Calls the SendInput function to send the VK_SHIFT + VK_OEM_2 keystrokes instead of the Aleph character.

The main problem here is that to send a Unicode character, SendInput must be called with the KEYEVENTF_UNICODE flag and the character in question must be passed via the function parameters — the experiment shows that none of this is the case. Also, VkKeyScan isn't actually needed in case of a Unicode character, as SendInput itself handles Unicode input.


Given this, the only way to send Unicode input to an application from VBScript is to write a custom utility or COM component that will utilize SendInput properly and to call this utility/component from your script. (VBScript doesn't have any native means to access Windows API.)

Note added by barlop

While vbscript's obj.SendKeys(..) isn't unicode aware, VB's SendKeys.Send(..) would be.

I'm using Dragon Naturally Speaking with hebrew, and SendKeys indeed cannot send hebrew characters even though they show in the macro editor, however, what I did was set the clipboard with the hebrew text that I wanted, and then SendKeys with Ctrl-V for paste, and that does works, it's just SendKeys that messes with the encoding.

Clipboard("טקסט בעברית")
SendKeys("^V")

That would override the users clipboard and won't work for mixing command characters (Ctrl,Alt,Shift) with hebrew characters, but it's a work around.

Try setting the font to Microsoft Sans Serif in Notepad.

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