Jump to content

Help me with loop script


 Share

Recommended Posts

Hi all,

Im completely newbie here. I have a problem with script that really need your help.

I want: When I press right mouse, number 2 will be pressed and it will loop per 5s. And it only stop ( I mean stop/script but not close it)  when I press enter key. Here is my script:

While 1
    If _ispressed("2") Then
        While _ispressed("2")
                Send("62")
                    Sleep(50)
        WEnd
    EndIf
WEnd
Func if _ispressed("2") Then
            Send("62")
            Sleep(5000)
EndFunc

Func TogglePause(0D) 
EndFunc

Thank very much!!

 

Link to comment
Share on other sites

This script has so many problems, I don't know where to start. Try reading some example scripts and searching for all the errors you get running this script, so you can at least either provide a version without the syntax errors, or ask about the specific errors you don't know how to fix.

Also, this is a strangely specific to want to automate. What application are you automating? There is probably a much better way to accomplish what you are trying to do.

Edited by SadBunny
tpyo

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

I got a feeling this is gonna be locked soon.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • Developers
1 hour ago, careca said:

I got a feeling this is gonna be locked soon.

No need for any suggestive remarks and just let the thread run its course.

Jos

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

13 hours ago, SadBunny said:

This script has so many problems, I don't know where to start. Try reading some example scripts and searching for all the errors you get running this script, so you can at least either provide a version without the syntax errors, or ask about the specific errors you don't know how to fix.

Also, this is a strangely specific to want to automate. What application are you automating? There is probably a much better way to accomplish what you are trying to do.

Thanks SadBunny. I find the first script on internet and it work good.

While 1
    If _ispressed("2") Then
        While _ispressed("2")
                Send("62")
                    Sleep(50)
        WEnd
    EndIf
WEnd

But I want more for my requirement so I change some on it which you see :D

If you feel hard to fix it, so pls you can help me write a new script? I thanks alot.

I use "Editor SciTE4" to edit the script.

Link to comment
Share on other sites

14 hours ago, PhuongDuy said:

Hi all,

Im completely newbie here. I have a problem with script that really need your help.

I want: When I press right mouse, number 2 will be pressed and it will loop per 5s. And it only stop ( I mean stop/script but not close it)  when I press enter key. Here is my script:

While 1
    If _ispressed("2") Then
        While _ispressed("2")
                Send("62")
                    Sleep(50)
        WEnd
    EndIf
WEnd
Func if _ispressed("2") Then
            Send("62")
            Sleep(5000)
EndFunc

Func TogglePause(0D) 
EndFunc

Thank very much!!

 

Please use screenshot.1.jpg when posting code.

I would suggest:

  • a low level mouse hook for the mouse events here is a thread with some example code
  • AdlibRegister for the loop you need to repeat every 5 seconds
  • maybe a low level keyboard hook for the enter key, but it might be overkill, so a simpler implementation would be HotKeySet
Link to comment
Share on other sites

51 minutes ago, genius257 said:

Please use screenshot.1.jpg when posting code.

I would suggest:

  • a low level mouse hook for the mouse events here is a thread with some example code
  • AdlibRegister for the loop you need to repeat every 5 seconds
  • maybe a low level keyboard hook for the enter key, but it might be overkill, so a simpler implementation would be HotKeySet

OK, will notice it genius257.

I wish i can understand all your link...Im COMPLETELY NUMBER ZERO KNOWLEDGE on experience at coding scripts ~~!!!

Link to comment
Share on other sites

Maybe something like this, haven't really tested, but might give you something to work from.

#include <Misc.au3>

Global $bSTOP = False

HotKeySet('{Esc}', '_FNC_EXIT')
HotKeySet('{Enter}', '_FNC_STOP')

While 1
    If _IsPressed('02') Then _FNC_TIME()
    Sleep(50)
WEnd

Func _FNC_STOP()
    If $bSTOP = False Then
        $bSTOP = True
    Else
        $bSTOP = False
    EndIf
EndFunc

Func _FNC_TIME()
    $bSTOP = False
    Send('{ALT}')
    Local $hTIME = TimerInit(), $hDIFF = 0
    While 1
        Send('{NUMPAD2}')
        $hDIFF = TimerDiff($hTIME)
        If $hDIFF >= 5000 Then $bSTOP = True
        If $bSTOP = True Then ExitLoop
        Sleep(50)
    WEnd
EndFunc

Func _FNC_EXIT()
    Exit
EndFunc

 

Link to comment
Share on other sites

Hi Subz,

I just run your script. It work with no error debug found. But it seem not like what i need. When i press right mouse, script do 22222222222222222222222222 (may be in 5s) and stop. I mean "press" is "click" (not press and hold mouse in 5s :D). Pls help me fix it. Here is my expectation for script:

1. When click right mouse

2. Script do number 2 and stop in 5s. Then do number 2 and stop in 5s again.. and repeat this loop...

3. Script will just stop (not exit)  when I click enter. If I click right mouse again, script will start running

Thanks alot!

Link to comment
Share on other sites

You mean something like this?

#include <Misc.au3>

Global $bSTOP = False

HotKeySet('{Esc}', '_FNC_EXIT')
HotKeySet('{Enter}', '_FNC_STOP')

While 1
    If _IsPressed('02') Then _FNC_TIME()
    Sleep(50)
WEnd

Func _FNC_STOP()
    If $bSTOP = False Then
        $bSTOP = True
    Else
        $bSTOP = False
    EndIf
EndFunc

Func _FNC_TIME()
    $bSTOP = False
    Local $hTIME = TimerInit(), $hDIFF = 0
    Send('{NUMPAD2}')
    While 1
        $hDIFF = TimerDiff($hTIME)
        If $hDIFF >= 5000 Then
            Send('{NUMPAD2}')
            $hTIME = TimerInit()
        EndIf
        If $bSTOP = True Then ExitLoop
        Sleep(50)
    WEnd
EndFunc

Func _FNC_EXIT()
    Exit
EndFunc

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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