Jump to content

Recommended Posts

Posted

Hello,

I hope I asking this question in the right forum. 

Issue: Below I have a short piece of code that seems to be miss behaving.  Underscores are being converted to dashes on chrome browser for sending keys. (This does not happen in Firefox)

While we are using it internally, I found a external scenario to prove its not specific to our system.  I am using ControlSend instead of Send because our users have a chat window that will move to the top and take focus.  Send will type in the chat windows instead of the required window.

The program open Google accounts ("https://accounts.google.com/") on Chrome in a private (incognito) window. then autotypes into the first field.

The last line sends j_test but j-test shows up in the Chrome browser.

Any help would be appreciated.  Thanks, Jeff

Attempted workarounds:
1. putting the underscore inside brackets {_}
2. using ASC(95) 
3. Using ASCW(95)
4. Send("keys") doesn't convert to dash but can lose focus from chat software

Code:
#include <WinAPI.au3>
;Testing ControlSend in browser string is j_test but j-test get displayed
;Google Account - Close Chrome browser before starting.
$url = "https://accounts.google.com/"

Run('cmd /c "start chrome" ' & $url & ' --incognito --new-window ')

Sleep(2000)    ; Wait for 2 seconds.

Local $hWnd = WinGetHandle("[CLASS:Chrome_WidgetWin_1]")

Sleep(2000)    ; Wait for 2 seconds.

WinActivate(_WinAPI_GetParent($hWnd), "")

Local $hControl = ControlGetHandle($hWnd, "", "Edit1")

ControlSend("[CLASS:Chrome_WidgetWin_1]", "", "", "j_test")

Desktop:
Windows V10
Autoit V3.3.16.1

Posted

 

#include <WinAPI.au3>
;Testing ControlSend in browser string is j_test but j-test get displayed
;Google Account - Close Chrome browser before starting.
$url = "https://accounts.google.com/"

Run('cmd /c "start chrome" ' & $url & ' --incognito --new-window ')

Sleep(2000)    ; Wait for 2 seconds.

Local $hWnd = WinGetHandle("[CLASS:Chrome_WidgetWin_1]")

Sleep(2000)    ; Wait for 2 seconds.

WinActivate(_WinAPI_GetParent($hWnd), "")

Local $hControl = ControlGetHandle($hWnd, "", "Edit1")

;~ ControlSend("[CLASS:Chrome_WidgetWin_1]", "", "", "j_test")
ControlSend($hWnd, "", $hControl, "j_test")

 

I know that I know nothing

Posted (edited)

with a second look

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

$url = "https://accounts.google.com/"
Run('cmd /c "start chrome" ' & $url & ' --incognito --new-window ')

Local $hWnd = WinWait("- Google Chrome")
Sleep(2000)    ; Wait for 2 seconds.

Local $hControl = ControlGetHandle($hWnd, "", "Edit1")

ControlSend($hWnd, "", $hControl, "j_test")

 

how-to-post-code-on-the-forum

:welcome: to forum

Edited by ioa747

I know that I know nothing

Posted
1 hour ago, jjt35m said:

Underscores are being converted to dashes on chrome browser for sending keys.

Opt("SendKeyDelay", 25)
Opt("SendKeyDownDelay", 25)

ControlSend simulates keystrokes, so technically it sends shift and dash when you want to send underscore. If delay between keystrokes is too short, some keys may not be sent at all.

Posted

Your intend is to send text to an edit-control.
The problem is you are sending text to the Chrome window control because you left the third parameter of ControlSend empty (controlID = "").
It seems like this window control then 'sanitizes' the text before transferring the text to the likely intended control, the edit-control.
If you use the $hControl as third parameter your problem will be solved. 

You are using ControlSend to send usernames / emailadresses to an edit-control. I am not sure if these can contain the special characters like !, # etc. but with the default for the flag-parameter these will cause problems. So it is better to use the flag-raw parameter. But because underscore is not special for Send/ControlSend this will not solve your current problem.

An alternative might be the use of ControlCommand with the "EditPaste"-option.
 

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
×
×
  • Create New...