Renderer Posted August 10, 2019 Share Posted August 10, 2019 Hi guys, I want to ask you a question regarding the while loops. How can I prevent an action from repeating when it is in a while loop: Take a look at the script below: #include <misc.au3> global $body = GUICreate("Simple Window",430,340) GUISetState() while 1 switch GUIGetMsg() case -3 exitloop endswitch if _ispressed("0d") then GUICtrlCreateLabel("Some Text Here",10,10,120,20) endif ;it keeps running on and on ; ... wend How can I prevent the script from repeatedly creating the label when I press the button. Thanks in advance! Link to comment Share on other sites More sharing options...
Nine Posted August 10, 2019 Share Posted August 10, 2019 Try this : #include <misc.au3> Global $body = GUICreate("Simple Window", 430, 340) Local $idDum = GUICtrlCreateDummy() Local $aKey[1][2] = [["{ENTER}",$idDum]] GUISetAccelerators($aKey) GUISetState() While 1 Switch GUIGetMsg() Case -3 ExitLoop Case $idDum GUICtrlCreateLabel("Some Text Here", 10, 10, 120, 20) GUISetAccelerators("") ConsoleWrite ("check if only once" & @CRLF) EndSwitch WEnd “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Bilgus Posted August 10, 2019 Share Posted August 10, 2019 (edited) The helpfile mentions this specifically.... Quote _IsPressed() will return 1 until the key is released.Even brief key presses can result in multiple returns within a loop. If the code called does not include a blocking function (such as MsgBox) and the user does not require multiple returns, the script should wait until _IsPressed() returns 0 before continuing. https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm #include <misc.au3> #include <GUIConstantsEx.au3> global $body = GUICreate("Simple Window",430,340) GUISetState() while 1 switch GUIGetMsg() case $GUI_EVENT_CLOSE exitloop endswitch if _ispressed("0d") then ;Enter Key while _ispressed("0d") <> 0 ; wait till released Wend GUICtrlCreateLabel("Some Text Here",10,10,120,20) ConsoleWrite ("check if only once" & @CRLF) endif ;it keeps running on and on ; ... wend Edited August 10, 2019 by Bilgus FrancescoDiMuro 1 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