JohnyX Posted October 1 Share Posted October 1 Hello, I have a GUI as in the attached image. When I click the button, the text should be inserted into the active cell as copy-paste (Ctrl+C & Ctrl+V) , but it is not, since it will switch focus from Excel to GUI when the button is clicked. The excel is just an example, it could be any other application. Is there a way to keep the GUI on top and also "lose" it's focus at the same time so that the text can be submitted to other window on button click? ย Thank you. Link to comment Share on other sites More sharing options...
Solution SOLVE-SMART Posted October 1 Solution Share Posted October 1 (edited) Hi @JohnyXย ๐ , please: next time let us see an example script of yours. Show a bit more effort, this would make our live and yours more easy. Fortunately I had a similar script laying around and only had to adjust some things. That's a example which does not contain error handling etc., but your attention should be going to the $iGuiTopMostFlag (*\AutoIt3\Include\WindowsConstants.au3) and the WinActivate() function. expandcollapse popup#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y Global $hGui _Main() Func _Main() _OpenNotepad() _ShowGui() _Teardown() EndFunc Func _OpenNotepad() Run('notepad.exe') EndFunc Func _ShowGui() Local Const $iGuiTopMostFlag = 0x00000008 GUICreate('Form1', 300, 200, Default, Default, Default, $iGuiTopMostFlag) Local Const $cIdInput = GUICtrlCreateInput('Text to insert', 15, 15, 150) Local Const $cIdButton = GUICtrlCreateButton( 'Insert', 15, 45, 150) GUISetState(@SW_SHOW) Local Const $iGuiCloseFlag = -3 While True Switch GUIGetMsg() Case $iGuiCloseFlag ExitLoop Case $cIdButton _Insert(GUICtrlRead($cIdInput)) EndSwitch WEnd EndFunc Func _Insert($sText) ClipPut($sText) Opt('WinTitleMatchMode', 2) WinActivate('Editor') Opt('WinTitleMatchMode', 1) ; reset to default Send('^v') EndFunc Func _Teardown() ProcessClose('notepad.exe') GUIDelete($hGui) EndFunc I guess this should be helpful, right? Best regards Sven Edited October 1 by SOLVE-SMART Stay innovative! Spoiler ๐ย Au3Forums ๐ฒ AutoIt (en) Cheat Sheet ๐ AutoIt limits/defaults ๐ Code Katas: [...] (comming soon) ๐ญ Collection of GitHub users with AutoIt projects ๐ย False-Positives ๐ฎย Me on GitHub ๐ฌย Opinion about new forum sub category ๐ย UDF wiki list โย VSCode-AutoItSnippets ๐ย WebDriver FAQs ๐จโ๐ซย WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
JohnyX Posted October 1 Author Share Posted October 1 Hello, Sven, This is perfect. I will also share my trial code in the future. Thanks a lot. John ย 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