Sign in to follow this  
Followers 0
emendelson

"Send" a string one char at a time, replacing some of them?

8 posts in this topic

I think this problem has been solved already, but I can't find all the pieces that need to be put together, so I would be grateful for any help.

I am writing a script that will paste the contents of the Windows clipboard into the DOSBox DOS emulator. To do this I, use this function:

#include <WinAPI.au3>
Func ClipboardPaste()
$textto = ClipGet()
$iCodePage = 1 ;; 1 uses OEM string of current system
$clipUnicode = _WinAPI_WideCharToMultiByte($textto, $iCodePage, True)
$clipUnicode = StringTrimRight($clipUnicode, 1)
$textto = $clipUnicode
If @error Then
  $textto = " "
EndIf
If WinActive("DOSBox") Then
  Send($textto, 1)
EndIf
EndFunc   ;==>ClipboardPaste

The trouble with this is that it can't "send" upper ASCII characters like ç, é, ü, because the only way to type them into DOSBox is by turning NumLock on and typing Alt-0130 or some similar number.

What I would like to do is parse the text in $textto, one character at a time. If the character is in an array that includes upper ASCII characters (ç é ü etc.), then I would "send" something like "{NUMLOCK on}!{NUMPAD1}!{NUMPAD3}!{NUMPAD0}{NUMLOCK off}". If the character is not in the array, I would simply send the character.

I realize this would be very slow, but it would be better than nothing. Does any code already exist that would accomplish this? If so, could someone post it here?

Many thanks in advance.

Share this post


Link to post
Share on other sites



Use the Chr() function to send the ASCII code for the character you need, that should work better.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Use the Chr() function to send the ASCII code for the character you need, that should work better.

Thank you! Unfortunately, DOSBox emulates an old MS-DOS machine, and so it does not understand Chr(nn) input. Chr(nn) works for Chr(20) through Chr(127) (or approximately), but not for anything else. The only way to type an accented character into DOSBox is to type it in the same way it got typed in old DOS machines - by holding down Alt and typing the correct number on the numeric keypad, or by pressing NumLock and then typing Alt-130 (or some other number above 128). That's what I'm trying to do.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I would "send" something like "{NUMLOCK on}!{NUMPAD1}!{NUMPAD3}!{NUMPAD0}{NUMLOCK off}"

It looks like the problem is that you are sending three different ALT sequences, ALT-1 then ALT-3 then ALT-0. Instead, try "{NUMLOCK on}{ALTDOWN}{NUMPAD1}{NUMPAD3}{NUMPAD0}{ALTUP}{NUMLOCK off}".

Edit: The following works for me in a CMD prompt...

WinActivate("C:\Windows\System32\cmd.exe")
WinWaitActive("C:\Windows\System32\cmd.exe")
Send("{ALTDOWN}{NUMPAD1}{NUMPAD3}{NUMPAD0}{ALTUP}")
Edited by JohnQSmith

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites

Thank you for this. That is clearly the method I need to use to enter upper ASCII characters. It works perfectly in DOSBox.

Now the problem that baffles me is this:

How do I build two arrays, one with a list of characters like é, ç, ü, etc., the other with a list of strings like ("{NUMPAD1}{NUMPAD3}{NUMPAD0}") that I can use in a variable. Basically, what I am trying to do is this:

1. Read the Windows clipboard (no trouble; see the code in my first post).

2. Read each character of the string in the clipboard, one by one. It might contain "This is my résumé", for example

3. After reading each character, if the character is a standard lower-ASCII character (like T, h, i, s, etc), send it to the current window.

4. But if the character is an upper-ASCII character like é, then look it up in the array to find a series of {NUMPAD#} strings to send instead (the NUMPAD# characters would come between {ALTDOWN} and {ALTUP}).

So the problem is first, to read each character, then tosee if it is in my array of upper-ASCII characters, and then either send the "raw" character or send the string of codes.

Thanks again for any help.

Share this post


Link to post
Share on other sites

Here's what I put together real quick.

$input = "How do I build two arrays, one with a list of characters like é, ç, ü, etc. Read each character of the string in the clipboard, one by one. It might contain This is my résumé"
$inputArray = StringToASCIIArray($input)
$output = ""
For $i = 0 to UBound($inputArray)-1
    Switch $inputArray[$i]
        Case 32 to 126
            $output = $output & Chr($inputArray[$i])
        Case 128 to 255
            $temp = String($inputArray[$i])
            $output = $output & "{ALTDOWN}"
            For $j = 1 to 3
                $output = $output & "{NUMPAD" & StringMid($temp,$j,1) & "}"
            Next
            $output = $output & "{ALTUP}"
    EndSwitch
Next
Send($output)
ConsoleWrite($output)

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites

That's amazingly helpful - I can't thank you enough. I think that does exactly what's needed. I thought it would be far more complicated than this, requiring two separate arrays, but this avoids that problem entirely. Thank you a thousand times!

Share this post


Link to post
Share on other sites

Thanks again to JohnQSmith. His solution is elegant and fast. I had to make two slight changes to get it work perfectly, and they're noted in the code below:

$input = "How do I build two arrays, one with a list of characters like é, ç, ü, etc. Read each character of the string in the clipboard, one by one. It might contain This is my résumé"
$inputArray = StringToASCIIArray($input, 0, StringLen($input), 1) ; added parameters for full character set
$output = ""
For $i = 0 to UBound($inputArray)-1
    Switch $inputArray[$i]
     Case 9 to 13 ; added tab, return, etc. characters
            $output = $output & Chr($inputArray[$i])
        Case 32 to 126
            $output = $output & Chr($inputArray[$i])
        Case 128 to 255
            $temp = String($inputArray[$i])
            $output = $output & "{ALTDOWN}"
            For $j = 1 to 3
                $output = $output & "{NUMPAD" & StringMid($temp,$j,1) & "}"
            Next
            $output = $output & "{ALTUP}"
    EndSwitch
Next
Send($output)
ConsoleWrite($output)

Thank you again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0