AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unicode characters to PowerPoint, Notepad...
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Wed Feb 23, 2005 11:36 pm    Post subject: Unicode characters to PowerPoint, Notepad... Reply with quote

I keep struggling with Unicode character entry. Some applications, like PowerPoint of MS Office XP, Win2K Notepad or all the ones with standard Windows edit controls can handle Unicode well, but the Alt-Numpad method does not work to enter the characters. Alt-945 should produce α, but these applications show an ANSI character as if only the last byte of the character code was typed. The same happens with Send {ASC 945} from AutoHotKey.

It is especially painful in PowerPoint, where the nice characters could really spice up your presentations. The Insert / Symbol method is very slow.

There should be a way to send Unicode to PowerPoint and Notepad (without the complicated way of pasting it from the Clipboard or from the symbol table). Some keyboard drivers do it (like Keyman). Does anyone know, how?
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Thu Feb 24, 2005 1:16 am    Post subject: Reply with quote

If you haven't already, try "Transform Unicode". It allows a script to put Unicode characters directly onto the clipboard.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Thu Feb 24, 2005 2:51 am    Post subject: Reply with quote

This is what I wanted to avoid. Since we cannot save/restore graphic clipboards, the sidefects are serious.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Thu Feb 24, 2005 3:17 am    Post subject: Reply with quote

The AutoHotKey sample code to get the Unicode clipboard converted to an ASCI string:
Code:
^!u:: ; Control+Alt+U
MsgBox Copy some Unicode text onto the clipboard, then return to this window and press OK to continue.
Transform, ClipUTF, Unicode
Clipboard = Transform, Clipboard, Unicode, %ClipUTF%`r`n
MsgBox The clipboard now contains the following line that you can paste into your script. When executed, this line will cause the original Unicode string you copied to be placed onto the clipboard:`n`n%Clipboard%
return
When α is copied to the Clipboard, the script shows in the MsgBox
Quote:
α


Last edited by Laszlo on Fri Feb 25, 2005 2:31 am; edited 3 times in total
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Thu Feb 24, 2005 3:29 am    Post subject: Reply with quote

The following works with Notepad and WordPad
Code:
^!v:: ; Control+Alt+V
Transform, Clipboard, Unicode, α
Send ^v
return

Except, the Clipboard gets destroyed.


Last edited by Laszlo on Fri Feb 25, 2005 2:28 am; edited 1 time in total
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Thu Feb 24, 2005 1:45 pm    Post subject: Reply with quote

Laszlo wrote:
but the simple Send
Send %Clipboard%[/code]does not.
Still, the Clipboard gets destroyed.
Yes, that is a known limitation. Hopefully someday there will be a pure Unicode version of AutoHotkey that can load and process scripts written in Unicode text.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Thu Feb 24, 2005 2:58 pm    Post subject: Reply with quote

I don't think a Unicode version of AutoHotKey is important, but extending the Send command to handle {ASC 945} in Unicode applications is.
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 2952
Location: Minnesota

PostPosted: Thu Feb 24, 2005 3:05 pm    Post subject: Reply with quote

Quote:
I don't think a Unicode version of AutoHotKey is important,


Probably because you're from Pittsburgh. Wink Or had you not noticed that a sizable proportion of this community is European?
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Thu Feb 24, 2005 3:29 pm    Post subject: Reply with quote

Quote:
Or had you not noticed that a sizable proportion of this community is European?
Eh, we've survived G.W.'s visit yesterday, guess that suggestion was kinda revenge ... Razz
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Thu Feb 24, 2005 3:35 pm    Post subject: Reply with quote

Hey, I just work here! You could have guessed that I am Hungarian, why should I otherwise bother to type letters like Ő. Have you seen a native American doing this? (Actually, I have. Knuth made TeX capable of handling diacritical letters, like the á and ő in the name Pál Erdős, for proper bibliographic references.)

Once I tried the German version of the MS Word macro language (Visual Basic). The keywords, commands were in German. It was just horrible. You had to remember two sets of reserved words and their shorthands and spellings, because other versions of Visual Basic still required English for their reserved words. You have to learn the programming language anyway, so it makes not much of a difference if you type your program with English commands or in your native language. (English is even easier than writing a program, e.g. in Chinese. I guess.)

But the input/output of the program you write must be able to handle foreign languages. That is, the strings have to be allowed to contain all the funny characters, maybe in the form of my favorite {ASC 945} and the commands Input, Send… should process them correctly. This is all what I am asking for.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Thu Feb 24, 2005 5:43 pm    Post subject: Reply with quote

After performing some experiments with the clipboard-workaround for pasting Unicode characters, I start to understand, that Unicoding is a hard problem. Some of the difficulties:
- Some Unicode characters are double width, so the insertion point has to move accordingly.
- Others are half width.
Entering them and then moving the insertion point to the left causes really funny behaviors of the editors (Notepad, WordPad, MS Word). Sometimes the caret moves two positions, sometimes it lands in the middle of the double-width character, etc.
- Some Unicode characters are meant for writing from right to left. The editors try to be smart, so the insertion point is left to the left of them.
- Some characters are interpreted by the editors as a command, and menus start to drop down, windows change, etc. With a simple loop of sending characters to WordPad I managed to crash Windows, corrupt open files, close applications without saving unfinished work, and so on.

It looks like the technology is not mature enough. At least in Windows. Cut-and-pasting characters using the Windows standard tools should not cause havoc to the OS. Still, diacritical letters and math symbols look safe, so Chris, let us have our fun with easier sending them from a script. It is so entertaining to see Windows go bazark…
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Thu Feb 24, 2005 9:39 pm    Post subject: Reply with quote

Laszlo wrote:
I don't think a Unicode version of AutoHotKey is important, but extending the Send command to handle {ASC 945} in Unicode applications is.
If I knew how to do it, I'd certainly try. As it stands now "Send {Asc nnnnn}" just simulates holding down the ALT key and pressing some keys on the number pad.

In other words, if you know a manual way to type Unicode characters that works universally in all Unicode text editors and word processors, I'd love to hear it. Such manual keystrokes could then be automated by the Send command.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Thu Feb 24, 2005 11:09 pm    Post subject: Reply with quote

Well, for XP Microsoft says the following:
http://www.microsoft.com/globaldev/DrIntl/columns/019/default.mspx
Quote:
Notepad on Windows XP:

Use the new <ALT> + <+> function for Notepad. What you do is while holding the Alt key press the + key on the numeric keypad followed by the Unicode hexadecimal number encoding (You need to remember to hold the key down until after you have typed in the hexadecimal encoding).

For example, here is how to input the Latin Capital Letter Æ whose encoding is U+00C6. While holding down the Alt key, you would type the numeric keypad's + then 00C6. After letting go of the Alt key, the "Æ" will appear in your Notepad file. (Note Preceding zeroes "0" can be left out, so you can also input "Æ" by only pressing the keypad's + then C6 while holding down the Alt key.) In summary the key sequence is:

Alt + <+> <Unicode Hex Value>

It does not work for me (my son's XP home edition, SP2). Nothing appears in Notepad.

Browsing MSDN I found a few interesting pages. But, again, I am not a programmer, so I cannot judge the usefulness of the information there.

About National Language Support
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_9rec.asp

Windows GDI: Font and Text Functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_9r77.asp
especially TextOut looks interesting. It accepts Unicode.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Fri Feb 25, 2005 1:27 pm    Post subject: Reply with quote

Thanks for the info. I think TextOut would not work because it simply draws the text you specify -- it doesn't actually send any characters anywhere, nor would it be appropriate to use it to draw text in a window belonging to some other process, such as Notepad.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 4510
Location: Boulder, CO

PostPosted: Sat Feb 26, 2005 3:59 am    Post subject: Reply with quote

I found a workaround for the Unicode-to-PowerPoint problem. It is not for the fainthearted, so those of you in this category stop reading right now. For the rest of you, fasten your seatbelts…

The Send command simulates keystrokes or sends ANSI characters to the active window. If an application does not support the ALT-NumKeys method, or some other keyboard-only way for entering Unicode characters, we are out of luck. The solution is to let Windows itself generate those Unicode characters and send them to the active application. Since AHK can control keystrokes, defining a special keyboard layout, with all the Unicode characters needed will solve our problems. AHK scripts will send the right keyboard entries and the keyboard driver sends the corresponding Unicode characters to the application.

The good news is that Microsoft provides the right tools for free (for Win2K, XP and Windows Server 2003), the Microsoft Keyboard Layout Creator (MSKLC):
http://www.microsoft.com/globaldev/tools/msklc.mspx

You start with loading your current keyboard layout into MSKLC. Find a key, which you can designate to be a "dead key". It means, it does not produce an output until one more key is pressed. If this key is defined to modify itself such a way, that it gives the original output, all what you loose is that this key has to be pressed twice to get its original character.

Having this dead key, we can assign as many Unicode characters to (modified) keys as we want or run out of keys. If that happens, we have to define a second dead key, too.

If you only need a few Unicode characters, this will be sufficient. Under the MSKLC menu item "Project" select "Build DLL and Setup Package". It creates and installable package, the keyboard name with .msi extension. Double clicking on it installs the new keyboard driver, what you can use after selecting it in the Control Panel / Keyboard option. The new keyboard happily sends the Unicode characters to all application ever after. (Some of them don't know, what to do with Unicode, so be careful.)

However, this method requires the user to remember which key is modified to give what Unicode character. If you misfire, you have to backspace and try it again. This is why I prefer the post modifier method. You press a key first, than modify it with a hotkey in a cycle, the last change always visible on screen, until you find what you need. Many small cycles work better than the dead key method. Fortunately, now an AHK script can easily produce those Unicode characters, which we just assigned to modified keyboard keys: the script sends the dead key and the base key to be modified. And we have its powerful scripting language for doing fancy things, like activating, de-activating Unicode characters in different windows, provide different tray icons to remind the user what key macros are active, selecting subsets of characters, remap the keyboard layout with a hotkey, etc.

My computer is used by other family members, too, so I would hear screams and receive abuse when they find a (dead) key behave unexpectedly. Fortunately, we have a 101-key keyboard, and MSKLC still lets you assign functions to the missing 102-th key found on other keyboards. So I chose this key to be the dead one, so the keyboard behaves exactly as before. No accidental Greek characters or stuttering keys. The dead key is only accessible as a virtual key from AHK or its siblings.

In the AHK script we have to use the corresponding virtual key with the right scan code. In my case it was E2. It is not easy to find, so keep this valuable information in secret, or give it away for really big money only. (Using the original keyboard driver I sent all the possible 256 hex values, one by one with Send {vkxx}. The 102-th key will produce a "\", so it narrows down to a choice between 2. The neighboring key scan codes reveal the real "\", which leaves you the scan code for the missing keyboard key.)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group