jjt35m Posted April 20, 2023 Posted April 20, 2023 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
ioa747 Posted April 20, 2023 Posted April 20, 2023 #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
ioa747 Posted April 20, 2023 Posted April 20, 2023 (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 to forum Edited April 20, 2023 by ioa747 I know that I know nothing
Nisteo Posted April 20, 2023 Posted April 20, 2023 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.
OJBakker Posted April 20, 2023 Posted April 20, 2023 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now