Jump to content

ControlSend modifies the string :(


 Share

Recommended Posts

Hello!

I'm trying to send variable "10000.10" to the form in some applycation.

If I have english keybord layout by default, and english layout by current, all works fine.

But if a have russian keybord layout by default (or by current), AutoIt prints "10000/10" to the form.

I can not use ControlSetText to this form because it's protected. Can only use Send or ControlSend.

I can not change layout by default, because users will be indignant.

What should I do?

Edited by Suppir
Link to comment
Share on other sites

You could use @KBLayout to check the language and decide what you have to send.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

You could use @KBLayout to check the language and decide what you have to send.

Does not work in this way.

I found a recept!

$var = "1000.10"

WinActivate("Our form")

Global $hWnd = WinGetHandle('') ; get handle to our application 

$def_lang = GetCurrentLayout($hWnd) ; remember current layout
if GetDefaultLayout() = 1 Then
    SetCurrentLayout('0419', $hWnd) ; if layout by default is russian then set current layout russian
Else
    SetCurrentLayout('0409', $hWnd) ; else set current layout english
EndIf

ControlSend("", "", "", $var) ; using ControlSend in "right" layout

SetCurrentLayout($def_lang, $hWnd) ; return our previous layout

Func GetCurrentLayout($hWnd)
    Local $Ret = DllCall('user32.dll', 'long', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0)
    $Ret = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', $Ret[0])
    Return Hex($Ret[0], 4)
EndFunc  

Func GetDefaultLayout()
    If @KBLayout = 00000419 Or @KBLayout = 0419 Then Return 1
    If @KBLayout = 00000409 Or @KBLayout = 0409 Or @KBLayout = 0809  Or @KBLayout = 00000809 Then Return 0
EndFunc
    
Func SetCurrentLayout($sLayout, $hWnd)
    Local $Ret = DllCall('user32.dll', 'long', 'LoadKeyboardLayout', 'str', StringFormat('%08s', StringStripWS($sLayout, 8)), 'int', 0)
    DllCall('user32.dll', 'ptr', 'SendMessage', 'hwnd', $hWnd, 'int', 0x0050, 'int', 1, 'int', $Ret[0])
EndFunc

The MAIN IDEA: you need to sinchronize our current layout and layout by default. Then ControlSend will work fine, else - it will modify our strings.

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...