WScript Sendkey doesn't accept Unicode Characters - unicode

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

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.

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.

Related

How to switch current IME using PowerShell?

I have created a script to add/remove (toggle) a specific IME. Now, after that IME is added, I want to switch to it, just as if I clicked the language name at the bottom right of the screen, and then clicked that IME on the pop-up list.
I have searched Google for this, but I could not find a suitable command. The top result was Set-WinDefaultInputMethodOverride, but I was not talking about changing the default IME or the precedence; I just want to automate the manual changing as described in the previous paragraph. Is that NOT possible with PowerShell?
You can shift the IME on or off with ALT + SHIFT in Windows and cycle through the languages. The easiest way to do this is with SendKeys.
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait('%+')
This will load the correct assembly and send the ALT+Shift keystroke. A list of special characters for SendKeys can be found here. On my system this changes the language from English to Japanese, a second [System.Windows.Forms.SendKeys]::SendWait('%+') will then cycle to Scottish Gaelic. Sending a third keystroke cycles back to English.
If the language has multiple inputs like Japanese Hiragana, half width Katakana, full width Katakana, etc... you can use ALT+~ to cycle those as well. Tilde must be escaped. [System.Windows.Forms.SendKeys]::SendWait('%{~}')
Note that the application you are attempting to enter text into has to support this though. For example Powershell itself will let me switch to Japanese but will not let me switch to Hiragana, only the standard ascii chars.
I'm not sure what your ultimate goal is but this is one way to shift through your installed languages via hotkeys.

Why can my AutoHotkey script only type some emoji?

I have set up a small AutoHotkey script that uses hotstrings to allow me to type a few emoji and other special characters:
#SingleInstance force
#Hotstring * ?
::–::–
::†::†
::π::𝜋
::&shrug;::¯\_(ツ)_/¯
::&tm;::™
::&c;::©
::&r;::®
::&tableflip;::(╯°□°)╯︵ ┻━┻
::&music;::♫
::&piano;::🎹
::&cmark;::✓
::&xmark;::✗
::&hourglass;::⌛
The script is also available on PasteBin.
It all works in my text editor:
However, some replacements don't work everywhere, for example in Telegram Desktop:
Both emoji were originally copied from Telegram Desktop, so they are definitely supported in it.
Why isn't this working as expected?
I'm running AutoHotkey Unicode 64-Bit in version 1.1.23.3 on Windows 10 (version 1511), Sublime Text 3 (3103) and Telegram Desktop 0.9.28.
I answered a similar question in the past: Autohotkey Replace 2 specific character with one
I don't really know what the problem was, but we managed to get around the problem by making use of the clipboard. Maybe the same method can be used for your scenario.

Need help troubleshooting AHK (Corrupted somehow?)

I used AutoHotKey for months with no issues, but now some (not all) of my shortcuts no longer work.
Any shortcut used to open a browser tab and go right to a site still work. For example, this…
#a::Run www.autohotkey.com
…will still bring a new tab into focus and load the AutoHotKey site when you press WIN+A. Similarly, everything I have to launch programs still works. But I was mostly using AHK to access accented letters or special characters on a laptop without a numpad. This…
!c::Send,ç
…used to produce a ç but now when you press ALT+c it generates this: ç
It doesn't seem to be tied exclusively to the ALT key. Even if I remap to avoid the ALT key I have the same issue. Below are (I believe) the affected bits in my *.ahk file.
Thanks to anyone who has ideas as to why this worked great and then one day stopped working! I would love to be able to use AutoHotKey again.
!a::Send,à
!b::Send,ß
!e::Send,è
#!e::Send,é
!i::Send,ï
!c::Send,ç
#!c::Send,Ç
!d::Send,·
!g::Send,?
!h::Send,?
!m::Send,—
!n::Send,ñ
!p::Send,¶
+!p::Send,þ
!s::Send,§
!x::Send,×
!'::Send,«
#!'::Send,»
!2::Send,²
!3::Send,³
!4::Send,¢
!7::Send,£
!=::Send,±
!/::Send,÷
+!/::Send,¿
!.::Send,…
What version of AutoHotkey are you using? Always use AutoHotkey and its documenatation from http://ahkscript.org/ (current uptodate version, new official website)! AutoHotkey and its documentation from autohotkey.com is outdated and you may have some problems using them!
Try to launch script with admin rights.
Turn of antivirus software and try if script works.
Check other software. Maybe some of them is using same shortcut?
Loading of UTF-8 macros containing national charactes doesn't work correctly if you have US keyboard active during the process. Switch to national keyboard, then reload the macro file.
For example, I'm using these locale/keyboards combinations and AHK script loads fine only with two:
When keyboard is switched to ENG-US, instead of success I get the following error (file is always the same, encoded in UTF-8):
---------------------------
AutoHotkey.ahk
---------------------------
Error at line 332.
Line Text: #ú::Send {Browser_Back}
Error: Invalid hotkey.
The script was not reloaded; the old version will remain in effect.
---------------------------
OK
---------------------------
With some other national characters, you don't get above error, but without a warning from AHK you get strange effects in interpretation of some UTF-8 characters.
AHK version: 1.1.16.05 (ahkscript.org)

Notepad++: Writing a run command using an installed plugin

I am trying to find a way to take the syntax highlighted text from N++ and then open it within say MS Word. I have found the plugin NppExport which can save the highlighted text to a rtf file. But it seems N++'s macros are not able to really utilize it. Any suggestions to automate this process? Thanks!
Basic steps are
1) call "Export to RTF"
2) Save to ${FULL_PATH_NAME}.RTF
3) open the RTF file
3) Open MS word
Note: I have 4 figured out using
"C:\Program Files\Microsoft Office\Office12\Winword.exe" /f "$(FULL_CURRENT_PATH)"
Since you are meshing two programs (Notepad++ and Word). It may be difficult to do totally in the macros. I haven't had much luck with the macros beyond repetitive text manipulation. But I can recommend the tool AutoHotKey (autohotkey.com) which makes implementing these tasks super simple. Here is a little example that I tried out. Yes it works.
^#R::
WinMenuSelectItem , ahk_class Notepad++,,Plugins, NppExport, Copy RTF to clipboard
SetTitleMatchMode, 2 ;find by partial title
WinActivate Microsoft Word
Send ^v
This will copy the text in RTF switch the active window to word and paste the code. It would be relatively simple to change the command to open a new window instead.

Unicode output on Windows command line?

I wrote a small Java application which output includes Unicode characters. When I use Eclipse to run it—I see all the output as expected.
The people who are supposed to use the application will run it as a jar file. I thought they could use standard cmd window, but in this window the Unicode appear as Gibberish.
Is there a way to make "cmd window" recognize the Unicode chars and display them properly?
Or, is there any tool to easily run the jar file and get the correct output?
BTW - redirecting the output to a file works okay, but the program is interactive, so this will not be a good solution.
Edit: Thanks everybody for the suggestions.
It seems that the cmd fonts don't have the specific characters I need, and this is why changing the code page did not solve my problem.
I found a way to add more monospaced fonts to the console, but after I add them any change that I want to do regarding the fonts (even choosing one of the original fonts in a different size) - is ignored.
I think that I will simply try with another tool, which supports chhosing a differnt font more easily.
Reference: Java Unicode on Windows Command Line
Try chcp 1252 or chcp 65001 from the command line. With Lucida Console or other font support.
try CMD /c /U java your.jar
The problem is the font with which the windows console is displaying output. Unfortunately for you, this is a user setting.
I recommend you suggest that your users set their windows console font to Lucida Console. That font should be able to handle wide/unicode characters.
In C++/C just use this: system("chcp 65001");
Don't forget to change the console's font to Lucida Console
For any answers, check it first. This is a simple console program, which verifies that changing the font actually does not work.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main( string[] args )
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine( "日本語です" );
Console.Write( "Finished. Press a key. " );
Console.ReadLine();
return;
}
}
}
I will check to see if the answer is concretely "Cannot be done". Other avenues to check: use a different shell. i.e. Powershell? I'll see if that works.
However, you could do:
ConsoleApplication1.exe > output.txt
notepad.exe output.txt
Disclaimer: My example is C#, but the console application should still work as such.
And view the results like that, in the meanwhile.
UTF-16 on cmd.exe
Open/run cmd.exe
Click on the icon at the top-left corner
Select properties
Then "Font" bar
Select "Lucida Console" and OK.
Write Chcp 10000 at the prompt
Finally dir /b
Also from
Is there a Windows command shell that will display Unicode characters?
CHCP 65001
DIR > UTF8.TXT
TYPE UTF8.TXT