Sign in to follow this  
Followers 0
waleed

Function Send + Arabic Characters

6 posts in this topic

#1 ·  Posted (edited)

Hello,

First, thank you for this great programme. It rally is very useful!

My question is this:- In a log-in situation where the username is in Arabic, the string appears 'garbaged', not the intended characters.

For example:

Send ("وليد") // that is "waleed" in Arabic

would print æáíÏ in the log-in field

I have considered and tried different ways without success, e.g. StringToASCIIArray, StringFromASCIIArray, Send("{ASC value}").

Is there a way to do it?

Thank you

Waleed

Edited by waleed

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hebrew arrays work well in my AutoIt programs. >_

Edited by Info

Share this post


Link to post
Share on other sites

There are a few parts of AutoIt that don't yet have full Unicode support. These are:

Send and ControlSend - Instead, Use ControlSetText or the Clipboard functions. 
Console operations are converted to ANSI.

These limits will be addressed in future versions if possible.

.

Share this post


Link to post
Share on other sites

Thank you very much for your response.

Best regards,

Waleed

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Taken from another thread but posted here because the code tags was corrupted:

Global Const $KEYEVENTF_KEYUP =2
Global Const $KEYEVENTF_UNICODE = 4
Global Const $INPUT_KEYBOARD = 1

Global Const $tagKEYBDINPUT = _
    'ushort wVk;' & _
    'ushort wScan;' & _
    'dword dwFlags;' & _
    'dword time;' & _
    'ulong_ptr dwExtraInfo'
    
Global Const $tagINPUT = _
    'dword type;' & _
    $tagKEYBDINPUT & _
    ';dword pad;' & _
    'dword pad'

Global $hDll = DllOpen('user32.dll')
Global $sString = "وليد "
Global $sTemp = ClipGet()


Run('notepad.exe')
WinWaitActive('[CLASS:Notepad]')

_SendEx($sString)

ClipPut($sString)
Send('^v')
ClipPut($sTemp)

DllClose($hDll)
Exit

Func _SendInputKB($iInputs, $pInputs, $iSize, $hDll = 'user32.dll')
    Local $aRet = DllCall($hDll, 'uint', 'SendInput', 'uint', $iInputs, 'ptr', $pInputs, 'int', $iSize)
    If @error Or Not $aRet[0] Then Return SetError(1, 0, False)
    Return SetError(0, 0, True)
EndFunc

Func _SendEx($sString)
    Local $tINPUT, $pINPUT, $iINPUT
    Local $iFlags, $iStrLen
    
    $iFlags = BitOR($KEYEVENTF_UNICODE, $KEYEVENTF_KEYUP)
    $iStrLen = StringLen($sString)
    
    $tINPUT = DllStructCreate($tagINPUT)
    $pINPUT = DllStructGetPtr($tINPUT)
    $iINPUT = DllStructGetSize($tINPUT)
    
        DllStructSetData($tINPUT, 'type', $INPUT_KEYBOARD)
        DllStructSetData($tINPUT, 'wVk', 0)
    
    For $i = 1 To $iStrLen
        DllStructSetData($tINPUT, 'dwFlags', $KEYEVENTF_UNICODE)
        DllStructSetData($tINPUT, 'wScan', AscW(StringMid($sString, $i, 1)))
        _SendInputKB(1, $pINPUT, $iINPUT, $hDll)
        
        DllStructSetData($tINPUT, 'dwFlags', $iFlags)
        _SendInputKB(1, $pINPUT, $iINPUT, $hDll)
    Next
EndFunc

When SciTE is configured to support encoding of UTF-8 with BOM everything is smooth.

You may drop all this and use ClipPut() and ClipGet() as it's much faster and involve no great overhead like _SendEx() involves.

Edit: ..Nevermind. The modified code:

Global Const $KEYEVENTF_KEYUP =2
Global Const $KEYEVENTF_UNICODE = 4
Global Const $INPUT_KEYBOARD = 1
Global Const $iInputSize = 28

Global Const $tagKEYBDINPUT = _
    'ushort wVk;' & _
    'ushort wScan;' & _
    'dword dwFlags;' & _
    'dword time;' & _
    'ulong_ptr dwExtraInfo'
    
Global Const $tagINPUT = _
    'dword type;' & _
    $tagKEYBDINPUT & _
    ';dword pad;' & _
    'dword pad;'

Global $hDll = DllOpen('user32.dll')
Global $sString = "وليد وليد وليد وليد "

Run('notepad.exe')
WinWaitActive('[CLASS:Notepad]')

_SendEx($sString)

DllClose($hDll)
Exit

Func _SendInputKB($iInputs, $pInputs, $iSize, $hDll = 'user32.dll')
    Local $aRet = DllCall($hDll, 'uint', 'SendInput', 'uint', $iInputs, 'ptr', $pInputs, 'int', $iSize)
    If @error Or Not $aRet[0] Then Return SetError(1, 0, False)
    Return SetError(0, 0, True)
EndFunc

Func _SendEx($sString)
    Local $tINPUTs, $pINPUTs, $iINPUTs
    Local $sStruct
    Local $iFlags, $iStrLen
    
    $iFlags = BitOR($KEYEVENTF_UNICODE, $KEYEVENTF_KEYUP)
    $iStrLen = StringLen($sString)
    
    $sStruct = ''
    
    For $i = 1 To $iStrLen * 2
        $sStruct &= $tagINPUT
    Next
    
    $tINPUTs = DllStructCreate($sStruct)
    $pINPUTs = DllStructGetPtr($tINPUTs)
    $iINPUTs = $iStrLen * 2
    
    For $i = 0 To $iStrLen-1
        Local $Temp = AscW(StringMid($sString, $i+1, 1))
        Local $iOffsetDown = $i * 8
        Local $iOffsetUp   = $i * 16
        
        DllStructSetData($tINPUTs, $iOffsetDown+1, $INPUT_KEYBOARD)
        DllStructSetData($tINPUTs, $iOffsetDown+3, $Temp)
        DllStructSetData($tINPUTs, $iOffsetDown+4, $KEYEVENTF_UNICODE)
        
        DllStructSetData($tINPUTs, $iOffsetUp+9, $INPUT_KEYBOARD)
        DllStructSetData($tINPUTs, $iOffsetUp+11, $Temp)
        DllStructSetData($tINPUTs, $iOffsetUp+12, $iFlags)
    Next
        
    _SendInputKB($iINPUTs, $pINPUTs, $iInputSize, $hDll)
EndFunc
Edited by Authenticity

Share this post


Link to post
Share on other sites

Hello,

Thank you very much indeed for the script.

I am going to study it and am sure it will be very useful.

Best regards,

Waleed

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