Jump to content

The "ENTER" key is in the infinite loop that I can't stop. - (Moved) - (Locked)


Go to solution Solved by Jos,

Recommended Posts

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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.

#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

 

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.

#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 by Maksymalny
Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

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

  • Developers
  • Solution

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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...