Zives

Sending commands through ControlSend

4 posts in this topic

Hello guys,

So, i have this routine that reads a single uppercase letter "A", and uses the ControlSend command to send it to a specific program but, sometimes it ends up sending the lowercase letter "a" (some kind of weird bug, if i test it on the notepad, it will work correctly). So i created this another routine to turn around this:

#include <Misc.au3>
#include <Array.au3>
#include <String.au3>
            
     Local  $sString1 = A
            $aArray2 = StringToASCIIArray($sString1)                            
            $sString2 = _ArrayToString($aArray2)                    
            $sString3 = _StringInsert($sString2, "{NUMPAD", 0)      
            $sString3 = _StringInsert($sString3, "},{NUMPAD", 8)
            $sString3 = _StringInsert($sString3, "}", 18)
            $aArray3 = StringSplit($sString3,",", 2)                
            _ArrayDisplay($aArray3)
            $sString2 = _ArrayToString($aArray3[0])
            $sString3 = _ArrayToString($aArray3[1])
            ControlSend($window, "", "", "{ALTDOWN}")
            ControlSend($window, "", "", $sString2)
            ControlSend($window, "", "", $sString3)
            ControlSend($window, "", "", "{ALTUP}")
            
            ;ConsoleWrite($sString2)

The "_ArrayDisplay($aArray3)" line brings me the wanted structure just for a check (2 rows each one with "NUMPAD6" and "NUMPAD5", the ASCII code for the uppercase "A") BUT, the ControlSend ends up sending " -1 " (this is what i get if a remove the semicolon from the consolewrite line ) instead of the "NUMPAD" elements that were saved in $sString2 and $sString3 and then, the ALT+65 intended comand to send the letter "A" doesn't works.

After some wondering, i found out that the {NUMPAD} comands have to be sent inside quotation marks like this "{NUMPAD}", but as they are inside a variable, i don't know to proceed. ( if i put the "" around the $sString, it will be sent as a text: $sString)

Does someone have any idea on how to turn around this?

Am i lacking expertise on how to build the ControSend Structure? (Im newbie on programming and sry for my english)
            

Share this post


Link to post
Share on other sites



On 21/12/2016 at 3:04 AM, genius257 said:

try one of these:

  • "+a"
  • "{ASC 065}"
  • "{ALTDOWN}{NUMPAD6}{NUMPAD5}{ALTUP}"

By the way the "$sString1" definition in your example is either missing single/double-quotes, or you're referring to a function named A, not included in your code

Actually The "$sString1" is just a variable/string that contains only the letter "A".

I know these input methods that you are talking about, but the main problem here is that the "A" is being transformed  into {NUMPAD6} and {NUMPAD5} and is being put inside another variables "$sString2" and "$sString3" and im not being able to send these elements {NUMPAD6} {NUMPAD5} that are inside these variables i.e.:

ControlSend($window, "", "", "{ALTDOWN} $sString2 $sString3 {ALTUP}")

$sString2 contains {NUMPAD6} as a text

$sString3 contains {NUMPAD5} as a text

But i can't put this to work...

Share this post


Link to post
Share on other sites
4 minutes ago, Zives said:

Actually The "$sString1" is just a variable/string that contains only the letter "A".

No not in your provided example:

On 21/12/2016 at 2:26 AM, Zives said:

 Local  $sString1 = A

To be a string, ti should be:

Local  $sString1 = "A"

 

6 minutes ago, Zives said:

inside these variables i.e.:

ControlSend($window, "", "", "{ALTDOWN} $sString2 $sString3 {ALTUP}")

$sString2 contains {NUMPAD6} as a text

$sString3 contains {NUMPAD5} as a text

But i can't put this to work...

It seems you want AutoIt to apple varaible values within double quoted string, like PHP?

As far as i know AutoIt does not offer that kind of functionallity.

So basically this shows what i mean:

$a = "test"
$b = "this is a $a"
MsgBox(0, "", $b);does not work as intended

you could do it like this:

ControlSend($window, "", "", "{ALTDOWN} "&$sString2&" "&$sString3&" {ALTUP}")

But if you wish to implement functionality, not provided naively by AutoIt, you would need to do something like StringRegExpReplaceCallback with a pattern like "[$][a-zA-Z_]+" and implement a function as the callback with the functionality to use Eval  to get the actual value and return it.

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