c.haslam Posted January 27, 2017 Share Posted January 27, 2017 The following script types an email address in Firefox. There is a shortcut on the Desktop which causes it to run when Ctrl+Alt+M is pressed. ;Local $wh = WinGetHandle("[ACTIVE]") ;If WinExists("[CLASS:MozillaWindowClass]") Then ; If WinActive("[CLASS:MozillaWindowClass]") Then Opt("SendKeyDelay",50) ControlSend("[CLASS:MozillaWindowClass]","","","x@gmail.com",1) ; EndIf ;EndIf ;WinActivate($wh) The code that is not commented out works, but it has a side-effect: Firefox loses focus. What changes to the script are required for Firefox to keep focus? Some of the commented-out code is my attempt. The second problem: if Ctrl+Alt+M is pressed when focus is on another application, e.g. TextPad, that application loses focus. How can it keep focus? You may ask: why would one want to have AutoIt type an address? For domestic harmony! ...chris Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
R0G Posted February 11, 2017 Share Posted February 11, 2017 The window does not need to be active when using ControlSend nor does ControlSend activate it. If you want to activate Firefox use WinActivate WinActivate ( "title" [, "text"] ) For the second problem you could use WinGetHandle to get active window handle, execute your code then restore previous window focus with WInActivate. ;Get active window handle Local $hWnd = WinGetHandle("") ;Your code here ;Restore focus to active window WinActivate($hWnd) Link to comment Share on other sites More sharing options...
c.haslam Posted February 11, 2017 Author Share Posted February 11, 2017 Thanks, Rog. Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
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