4

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!!

Community
  • 1
  • 1
workspace
  • 368
  • 1
  • 6
  • 16
  • 2
    The solution simply spells out that SendKeys is crippled by the way Microsoft introduced Unicode. Specifically, you are running into the problem that Windows narrow character sets are not supposed to be UTF-8. The workaround also mentioned is *not using WScript* for that, but going directly to the native wide API. – Deduplicator Apr 14 '14 at 11:21

2 Answers2

4

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.

Community
  • 1
  • 1
Helen
  • 87,344
  • 17
  • 243
  • 314
-1

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.

tony bd
  • 450
  • 2
  • 3
  • tonybd:-I tried your suggestion and changed my system Keyboard layout to French, it worked char for "à" but for char"æç" it gave me blank space. sorry i am not any to put <@tag> so specifically mentioned ur Name – workspace Apr 14 '14 at 14:29