PhuongDuy

Help me with loop script

13 posts in this topic

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!!

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

I got a feeling this is gonna be locked soon.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

Share this post


Link to post
Share on other sites
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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you mod! 

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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 ~~!!!

Share this post


Link to post
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

 

1 person likes this

Share this post


Link to post
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!

Share this post


Link to post
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

 

1 person likes this

Share this post


Link to post
Share on other sites

Hi Subz,

Its awesome. That is what i expect. Thank you very much :D

But later, if I change "Right Mouse" to " PgUp" key and "Enter" key to "PgDn" key, how should i do?

Share this post


Link to post
Share on other sites

I found it. I change "02" to "21" and "Enter" to PgDn" then it resolved. 

I appreciate you, Subz :)

Share this post


Link to post
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