views:

49

answers:

2

I am finding that VBscript's SendKeys does not support Unicode. It supports some like A-65, but not foreign letters like the letter Aleph (א) from the Hebrew alphabet. Prob outside its supported range. Could be for decimal values of 128+, it gives a "?", and it only supports the ASCII range.

I can type and see Hebrew letters on my computer using Windows XP. So the OS support for the characters is there and set up. My source code demonstrates that, since the line

msgbox Chrw(1488)

displays the Aleph character and I've displayed it in Notepad and MS Word.

It looks to me like it is sending a question mark for a character it doesn't recognize. I think MS Word or Notepad if they did have a problem displaying a character (e.g. when the font doesn't support a char), they would display a box rather than a question mark. Certainly in the case of Notepad anyway. So it looks like a SendKeys issue. Any ideas? Any kind of workaround?

Dim objShell

Set objShell = CreateObject("WScript.Shell")

objShell.Run "notepad" ''#can change to winword

Wscript.Sleep 2000

msgbox Chrw(1488)  ''#aleph

objShell.SendKeys ("abc" & ChrW(1488) & "abc")  ''#bang, it displays a ? instead of an aleph

WScript.Quit
A: 

Try setting the font to Microsoft Sans Serif in Notepad.

Trefex
No, see the original question: ”I think MS Word or Notepad if they did have a problem displaying a character (e.g. when the font doesn't support a char), they would display a box rather than a question mark. Certainly in the case of Notepad anyway.”
Philipp
right philipp. Also, arial, times new roman, or whatever font i'm using, certainly supports the aleph character.. and so naturally, changing to the ms sans serif font (another font that supports it) doesn't make it work.
barlop
Ok, worth a try.Mhhh
Trefex
Control Panel > Regional and Language Options > Advancedread: "This system setting enables non-Unicode programs to displays menus and dialogs in their native language. It does not affect Unicode programs, but it does apply to all users of this computer. Select a language to match the language version of the non-Unicode program you want to use." In the combo, select one of the Arabic language options.Reboot.What about this ?
Trefex
Trefix, I tried that, and I replied to helen's comment with what happened. It's an easy problem for you to reproduce and then you'd know it doesn't work! If you tried the code you'd see it won't work, and if by a change of language setting it suddenly worked, then you'd have the solution! But you don't. You'd see your suggestions aren't working if you tried them on your machine! but anyhow, as I said, Helen already inspired me then to try what you suggest now, and I had already replied with the results..before you suggested it, it didn't work.
barlop
Mhhh one of my comments are lost in translation apparently. I tried the code and I get a '?' both in the MsgBox and in Notepad. So I can't reproduce it at all. Now stop picking on me. I'm trying to help you out on a problem I don't have and won't require. I don't have to waste my time bothering to finding some way to make it work. I'm just trying to be nice.
Trefex
Trefex, i'm not picking on you, this is a technical discussion, so we both discuss things technically. You can criticise me technically, I can criticise your suggestions or ideas, technically. That is not a bad thing. And if you have big ears, i'm not bringing it up, that might be picking on you.
barlop
How dare you bring that up!! Well if I'd have the aleph char in the MsgBox I could actually try something. But for me I get ? no matter what I do. Sorry.
Trefex
Trefex. No need to apologize, you haven't done something bad. This is just a technical discussion. I'm not paying you to know something.
barlop
+2  A: 

You're most likely right in your guess that 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.)

Helen
Nice research..interesting.. I've seen some of that kind of thing in Visual Basic years ago (VK_SHIFT), the constants for various keys. Is that and access to the windows API available to the programmer in vbscript too? I don't seem to have a book that goes into it.I did find this link, somebody claiming to have written something to solve what looks like the equivalent problem, in visual basichttp://vb.mvps.org/samples/SendInput/I don't know if it's transferable to vbscript.
barlop
@barlop: No, VBScript doesn't have access to Windows API. However, you can create a custom utility that will utilize the necessary WinAPI functions and call this utility from VBScript code.
Helen