Silent_Adventure Posted February 7, 2019 Share Posted February 7, 2019 Hello Experts, I'm new to the forum and I'm a real Autoit enthusiast. Searching a lot for this question (disable an application GUI), I found several arguments, but since I'm at the beginning with Autoit programming, I can't figure out why the following lines don't work. The project I'm realizing is more complex, but my necessity is to obtain that a specific application GUI (MSWord) doesn't receive the user input commands (for example ENTER pressure), but only for a particular moment during the flow of script. I report a semplified example. My question is: in the five seconds afte the instruction " GUISetState(@SW_DISABLE, $hWnd)" if I interact with the instance of Notepad yet opened, the GUI receive all my inputs (as ENTER pressure, letters pressure, etc.). Probably I'm using the function GUISetState() as a real newbie. How to obtain the "freezing" of Notepad GUI? Any suggestion will be greatly appreciated. #include <AutoItConstants.au3> ;#include <GUIConstants.au3> ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ; Disable Notepad GUI. GUISetState(@SW_DISABLE, $hWnd) ; Wait for 5 seconds. - (If I press keys in this five seconds, the GUI doesn't appear as disable!) Sleep(5000) ; Enable Notepad GUI. GUISetState(@SW_ENABLE, $hWnd) ; Send the 'F5' key to the edit control of Notepad to display the date and time. The handle returned by WinWait is used for the "title" parameter of ControlSend. ControlSend($hWnd, "", "Edit1", "{F5}") ; Wait for 2 seconds. Sleep(2000) ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) ; Now a screen will pop up and ask to save the changes, the classname of the window is called ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file" WinWaitActive("[CLASS:#32770]") Sleep(500) Send("{TAB}{ENTER}") Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 8, 2019 Moderators Share Posted February 8, 2019 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Silent_Adventure Posted February 8, 2019 Author Share Posted February 8, 2019 Hello Melba, thank you for moving the topic in the right forum and I apologize for putting it here: inexperience to fill. Thanks for the clarification S_A Link to comment Share on other sites More sharing options...
caramen Posted February 8, 2019 Share Posted February 8, 2019 (edited) Hello, From what i understand you're just trying to block user's inputs at a specified moment. You can check in the help file. This macro : Blockinput (1) Be carefull you need admin rights for this. Help file : expandcollapse popup#RequireAdmin #include <AutoItConstants.au3> Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ; Disable user input from the mouse and keyboard. BlockInput($BI_DISABLE) ; Wait for 2 seconds. Sleep(2000) ; Send the 'F5' key to the edit control of Notepad to display the date and time. The handle returned by WinWait is used for the "title" parameter of ControlSend. ControlSend($hWnd, "", "Edit1", "{F5}") ; Enable user input from the mouse and keyboard. BlockInput($BI_ENABLE) ; Wait for 2 seconds. Sleep(2000) ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) ; Now a screen will pop up and ask to save the changes, the classname of the window is called ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file" WinWaitActive("[CLASS:#32770]") Sleep(500) Send("{TAB}{ENTER}") EndFunc ;==>Example To answer to the primary question: Your first script is not working becose you're not using the correct flag Try this one : #include <AutoItConstants.au3> ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ; Get GUI actual stat. $State = WinGetState($hWnd) ; Msg Actual stat MsgBox (0,'','OK:'&$State) Sleep (1500) ; Hide GUI WinSetState($hWnd, "", @SW_HIDE) ; Get GUI actual stat. $State = WinGetState($hWnd) ; Msg Actual stat MsgBox (0,'','OK:'&$State) Sleep (1500) ; Show Gui WinSetState($hWnd, "", @SW_SHOW) ;If $Stat = 13 Then ; ;EndIF To be familiar with all these flag and macro i recommand you to make some simple GUI and play with them. #include <AutoItConstants.au3> #include <GuiConstants.au3> $MyGui = GUICreate("test",300,300) $Button1 = GUICtrlCreateButton ( "Hit me!" , 100 ,100 ) $Button2 = GUICtrlCreateButton ( "Hit me!" , 100 ,130 ) GUICtrlSetState ($Button1 , $GUI_DISABLE ) GUISetState ( @SW_SHOW , $MyGui ) While (1) Sleep (10) ; Avoid CPU usage $GuiMsg = GUIGetMsg () ; Checking what is hapenning to $MyGui Switch $GuiMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;Button1 GUICtrlSetState ($MyGui , @SW_DISABLE ) ; = Nothing Case $Button2 _MyFirstFunction () ; Enable Button1 EndSwitch WEnd Func _MyFirstFunction () GUICtrlSetState ($Button1 , @SW_ENABLE ) EndFunc Regards, Edited February 8, 2019 by caramen Silent_Adventure 1 My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Silent_Adventure Posted February 8, 2019 Author Share Posted February 8, 2019 Hello Caramen! First of all, thank you very much for your very appreciated support. Yes, you fully understood my need. Reading the help, I tried the solution that you propose (even if you have a much superior style of writing the code). My problem is due to the fact that every time I call the Blockinput () function, a message rightly due to the #RequiredAdmin directive appears. My need to disable for an extremely short amount of time MSWord recurs many times during a working session of the Autoit script. In case it is useful I'll try to explain briefly what kind of work the script does. Perfect for your tip on the use of flags: in this aspect I'm particulary weak. Now I have to study and try your examples and follow the excellent advices. I'll update on the results. Thank you so much for your time and your expertise! Link to comment Share on other sites More sharing options...
caramen Posted February 8, 2019 Share Posted February 8, 2019 You're welcome. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Silent_Adventure Posted February 8, 2019 Author Share Posted February 8, 2019 Hello Caramen and to all, I studied and tried your three useful examples and I think I undestood how they work: very interesting. The "@SW_HIDE" flag work very well and hiding the GUI, the same doesn't receive commands. Now, since the appetite grow with eating, I would have a new question that rise in my mind. I would have the necessity that the MSWord GUI remain displayed on the screen, also in the short period of time when it became disable. This is possible in your opinion? Another solution come in my mind looking at your third script: I could disable and "freeze" all controls of MSWord and the text field where normally start a document (in my case a document is already present) Thank you for any suggestion Regards S_A Link to comment Share on other sites More sharing options...
caramen Posted February 9, 2019 Share Posted February 9, 2019 (edited) So if you dont got admin rights you cannot use BlockInput() that's all. But this is the only way for me to do what you want. An other simple way to disable a windows without block anyinput is a brain thing. You can move the windows out of the screen but it wont be displayed. Somthing like : WinMove ( $hWND , "" , -1000 , -1000 ) An other way ( Advanced skill ) would be to use : #include <WinAPI.au3> With some others macro. But unfortunatly we 're not learning this on the forum since it can make malicius things. Edited February 9, 2019 by caramen Silent_Adventure 1 My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Silent_Adventure Posted February 12, 2019 Author Share Posted February 12, 2019 Hello Caramen, thank you one more time for your hints. I started the week working quite hard so I reply you only this evening. But I kept in mind your suggestions and applied myself. Experimenting with Autoit Help file and following your suggestions, I solved. I believe that the function "GUISetState(@SW_DISABLE, $hwnd)" work only if the GUI is created with function $hwnd = GUICreate("title"). Instead seems me that this function doesn't work with the GUI of an already open MSWord instance. So I thought to try to open an embedded Notepad instance inside an Autoit GUI and try to disable it. And it work. It's possible to disable the interface... (of course mine are not statements, cause I always talk about my experiments, that are experiments of a real Autoit newbie!). This method already imply the "#include <WinAPI.au3>". And is not the better method since, when I try to embed the MS Word instance inside AutoIt GUI, all disappears. So I decided to try another way: keeping in mind your suggestion on "#include <WinAPI.au3>", and searching inside Autoit Help file, I found a one-instruction solution that work perfectly and directly on the MSWord GUI, without involving embedding or other complications. So thank you very much for your support! See you soon, Regards S_A 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