Maksymalny Posted September 21 Share Posted September 21 Hello. I just started using AutoIt and I'm pretty lost. I don't understand why this work that way and not in the way it suppose to. I have searched for the answer half day and I'm still in the same place even after several changes. I attached "F1" key as as HotKeySet to start the script, and it work, but it just start spamming the "Enter" key. In my perspective it should press 'Enter' key, wait 6 seconds, click "LShift" and than loop for holding a key should appear. As I had read on forum it should be made with while loop but maybe I understood something wrong. Then wait 2,5 seconds, press 'x' key, wait 250ms, and send 'Enter'. I don't understand why it still hitting the 'Enter' key if as someone said on the forum in few others questions about this topic, the 'w down is just a information for computer that the key is pressed but it will return single letter, in this example it would be 'w' if I would do just Send("{w down}") Sleep(50000) Send("{w up}") It would return single letter 'w', am I right? Question.au3 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 21 Moderators Share Posted September 21 Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team Maksymalny 1 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...
Dan_555 Posted September 22 Share Posted September 22 I made a debug version of your script. If you want to find out for yourself, what is going on, then run it first without reading the comment at the end of this post. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; Variable to control the loop Global $loopActive = False ; Set up hotkeys HotKeySet("{F1}", "ToggleLoop") HotKeySet("{p}", "StopScript") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 254, 232, 192, 114) Global $Edit1 = GUICtrlCreateEdit("", 2, 0, 247, 229) GUICtrlSetData(-1, "Edit1") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Write($txt) GUICtrlSetData ($Edit1,@HOUR & ":" & @MIN & ":" & @SEC & "> " & $txt & @CRLF,0) EndFunc Func ToggleLoop() Send("{F1}") Write("F1") $loopActive = Not $loopActive Send("{Enter}") Sleep(6000) Write("Enter") Send("{LSHIFT}") ; Press LSHIFT once ; Hold 'w' key for 50 seconds $endTime = TimerInit() + 50000 While TimerDiff($endTime) < 0 And $loopActive Send("{w down}") Write("W") Sleep(50) Send("{w up}") WEnd Sleep(2500) Send("x") Write("X") Sleep(250) Send("{ENTER}") Write("ENTER_2") Sleep(6000) EndFunc Func StopScript() $loopActive = False EndFunc You are setting a Global HOTkey to F1. Then you are sending (again globally) the same hotkey at the start of your hotkey script (the send ("{F1}"). Your script is calling its own hotkey and this creates an endless loop. Some of my script sourcecode Link to comment Share on other sites More sharing options...
Maksymalny Posted September 30 Author Share Posted September 30 (edited) On 9/22/2024 at 9:09 PM, Dan_555 said: I made a debug version of your script. If you want to find out for yourself, what is going on, then run it first without reading the comment at the end of this post. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; Variable to control the loop Global $loopActive = False ; Set up hotkeys HotKeySet("{F1}", "ToggleLoop") HotKeySet("{p}", "StopScript") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 254, 232, 192, 114) Global $Edit1 = GUICtrlCreateEdit("", 2, 0, 247, 229) GUICtrlSetData(-1, "Edit1") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Write($txt) GUICtrlSetData ($Edit1,@HOUR & ":" & @MIN & ":" & @SEC & "> " & $txt & @CRLF,0) EndFunc Func ToggleLoop() Send("{F1}") Write("F1") $loopActive = Not $loopActive Send("{Enter}") Sleep(6000) Write("Enter") Send("{LSHIFT}") ; Press LSHIFT once ; Hold 'w' key for 50 seconds $endTime = TimerInit() + 50000 While TimerDiff($endTime) < 0 And $loopActive Send("{w down}") Write("W") Sleep(50) Send("{w up}") WEnd Sleep(2500) Send("x") Write("X") Sleep(250) Send("{ENTER}") Write("ENTER_2") Sleep(6000) EndFunc Func StopScript() $loopActive = False EndFunc You are setting a Global HOTkey to F1. Then you are sending (again globally) the same hotkey at the start of your hotkey script (the send ("{F1}"). Your script is calling its own hotkey and this creates an endless loop. Hi! Thanks a lot for your answer! I was inaccessible for few days. You gave me amazing data to study from cause now I know I can see what is going on while my code is running. I don't understand why the while loop with timer isn't working. I mean this part of code is kinda skipping itself. I can see every single part of the code, I've edited to show me in GUI when 'w' key is pressed but it isn't pressing at all. I've edited some of the code and I tried to understand every line, and I do with exception of the loop. I'm attaching a new file with changes I've done to make everything clear. Question.au3 Edited September 30 by Maksymalny Link to comment Share on other sites More sharing options...
Nine Posted September 30 Share Posted September 30 Your loop is definitely problematic. Not even sure what you want to achieve exactly with it. But my first question is : What is the application you want to automate this way ? Looks to me it is for a game, right ? “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...
Maksymalny Posted September 30 Author Share Posted September 30 4 hours ago, Nine said: Your loop is definitely problematic. Not even sure what you want to achieve exactly with it. But my first question is : What is the application you want to automate this way ? Looks to me it is for a game, right ? Yes it's the application I would like to use is game. I would like to move my character and for that I need a loop that will repeat sending key that is assigned for movement. The best way for that is time value, I guess. Cause I don't know exactly how many characters I need to send to measure time, but it isn't working as expected. Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted September 30 Share Posted September 30 No one will give you a proper answer until a moderator will cancel your request, because you didn't read the forum rules. Please read them carefully. Best regards Sven 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...
Developers Solution Jos Posted September 30 Developers Solution Share Posted September 30 Welcome to the AutoIt forum. Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. See you soon with a legitimate question I hope. The Moderation team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts