Jump to content

Function Send + Arabic Characters


Recommended Posts

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
Link to comment
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.

.

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...