Jump to content
Sign in to follow this  
Jack023

Problems with loop.

Recommended Posts

Jack023

Hey all

This is my code,

#include <Misc.au3>
HotKeySet("[", "say")




Dim $v_array[10]

$v_array[0] = "CC0000"
$v_array[1] = "FF7F00"
$v_array[2] = "00ffff"
$v_array[3] = "b7102f"
$v_array[4] = "1648aa"
$v_array[5] = "ff41e9"
$v_array[6] = "ff00bf"
$v_array[7] = "32CD32"
$v_array[8] = '000000'



$i = 0

func say()
Local $hDLL = DllOpen("user32.dll")
Send("y")
$paste = ClipPut("" & $v_array[$i])
Send("{CTRLDOWN}v{CTRLUP}")
$i +=1
if $i = 7 Then $i = 0
if _IsPressed("20", $hDLL) Then

$paste = ClipPut("" & $v_array[$i])
Send("{CTRLDOWN}v{CTRLUP}")
$i +=1
EndIf
if _IsPressed("0D", $hDLL) Then
exit
EndIf


EndFunc

While 1
Sleep(1000)
WEnd

I the first part works: when I hit [ then it sends what I want.

Now the problem is:

Every time I hit space I want that it repeat the same except the send("y")

until I hit enter.

Can't get out how to do it using loops.

Thanks in advance

Edited by Jack023

Share this post


Link to post
Share on other sites
czardas

Is this what you want? I haven't tested the code and there are perhaps easier ways to do this.

:

#include <Misc.au3>
HotKeySet("[", "say")

Global $v_array[10] ; Why are you declaring 10 elements? <<<<<<<<<<<

$v_array[0] = "CC0000"
$v_array[1] = "FF7F00"
$v_array[2] = "00ffff"
$v_array[3] = "b7102f"
$v_array[4] = "1648aa"
$v_array[5] = "ff41e9"
$v_array[6] = "ff00bf"
$v_array[7] = "32CD32"
$v_array[8] = '000000'

func say()
    Local $hDLL = DllOpen("user32.dll")
    Send("y")
    
    Local $paste, $i = 0
    
    While 1
        $paste = ClipPut("" & $v_array[$i])
        Send("{CTRLDOWN}v{CTRLUP}")
        $i +=1
        If $i = 7 Then $i = 0
        If _IsPressed("20", $hDLL) Then
            $paste = ClipPut("" & $v_array[$i])
            Send("{CTRLDOWN}v{CTRLUP}")
            $i +=1
        EndIf
        If _IsPressed("0D", $hDLL) Then
            DllClose($hDLL) ; Close the Dll before you exit.
            Exit
        EndIf
    WEnd

EndFunc
Edited by czardas

Share this post


Link to post
Share on other sites
Jack023

Well almost,

enter works with ending only when I press [ it's spamming:

yCC0000FF7F0000ffffb7102f1648aaff41e9ff00bfCC0000FF7F0000ffffb7102f1648aa until I press enter.

The send("y") is good but I want like this:

Everytime when I hit enter 

$paste = ClipPut("" & $v_array[$i])
            Send("{CTRLDOWN}v{CTRLUP}")
            $i +=1

run this once, when i hit enter again do it again etc, until I hit enter then it stops and wait till i press [ again?

EDIT:
Got it working only have 1 problem left;

#include <Misc.au3>
HotKeySet("[", "say")

Global $v_array[10] ; Why are you declaring 10 elements? <<<<<<<<<<<

$v_array[0] = "CC0000"
$v_array[1] = "FF7F00"
$v_array[2] = "00ffff"
$v_array[3] = "b7102f"
$v_array[4] = "1648aa"
$v_array[5] = "ff41e9"
$v_array[6] = "ff00bf"
$v_array[7] = "32CD32"
$v_array[8] = '000000'
$i = 0
func say()
    Local $hDLL = DllOpen("user32.dll")
    Send("y")
        $paste = ClipPut("" & $v_array[$i])
        Send("{CTRLDOWN}v{CTRLUP}")
        $i +=1
        If $i = 8 Then $i = 0

    While 1

        If _IsPressed("20", $hDLL) Then
            $paste = ClipPut("" & $v_array[$i])
            Send("{CTRLDOWN}v{CTRLUP}")
            $i +=1
            If $i = 8 Then $i = 0

        EndIf
        If _IsPressed("0D", $hDLL) Then
            DllClose($hDLL) ; Close the Dll before you exit.
            Exit
        EndIf
    WEnd

EndFunc

While 1
    sleep(100)
WEnd

Number 1 is; when I hold the spacebar it do it more timers just want it one time until i press it again because you hold it pretty fast.

Number 2 is; when I press enter don't exit

Edited by Jack023

Share this post


Link to post
Share on other sites
czardas

Okay I'm outa time - gotta go. :( You said the first iteration was working and asked how to loop it. I should have tested it. Here is another attempt to fix your code, but I'm not entirely sure exactly what you want. The second example is how I would do what I think you want.

;

#include <Misc.au3>
HotKeySet("[", "say")

Global $v_array[10], $i = 0 ; Why are you declaring 10 elements? <<<<<<<<<<<

$v_array[0] = "CC0000"
$v_array[1] = "FF7F00"
$v_array[2] = "00ffff"
$v_array[3] = "b7102f"
$v_array[4] = "1648aa"
$v_array[5] = "ff41e9"
$v_array[6] = "ff00bf"
$v_array[7] = "32CD32"
$v_array[8] = '000000'

Func say()
    Local $hDLL = DllOpen("user32.dll")
    Send("y")

    Local $paste

    $paste = ClipPut($v_array[$i])
    Send("{CTRLDOWN}v{CTRLUP}")
    $i +=1

    While 1
        If $i = 7 Then $i = 0

        If _IsPressed("20", $hDLL) Then
            $paste = ClipPut($v_array[$i])
            Send("{CTRLDOWN}v{CTRLUP}")
            $i +=1
            ConsoleWrite($i & @LF)
        EndIf

        If _IsPressed("0D", $hDLL) Then
            DllClose($hDLL) ; Close the Dll before you exit.
            Exit
        EndIf
    WEnd

EndFunc

While 1
    Sleep(1000)
WEnd

;

How I would do what I think you're trying to do.

#include <Misc.au3>
 
HotKeySet("[", "say")
HotKeySet("{ENTER}", "Quit")

Global $v_array[10] ; Why are you declaring 10 elements? <<<<<<<<<<<

$v_array[0] = "CC0000"
$v_array[1] = "FF7F00"
$v_array[2] = "00ffff"
$v_array[3] = "b7102f"
$v_array[4] = "1648aa"
$v_array[5] = "ff41e9"
$v_array[6] = "ff00bf"
$v_array[7] = "32CD32"
$v_array[8] = '000000'

Global $i = 0, $bFirstRun = True, $hDLL = DllOpen("user32.dll")

Func Say()
    If $bFirstRun Then
        Send("y")
        $bFirstRun = False
    EndIf

    If $i = 7 Then $i = 0
    Local $paste = ClipPut($v_array[$i])
    Send("{CTRLDOWN}v{CTRLUP}")
    $i +=1
EndFunc

Func Quit()
    DllClose($hDLL) ; Close the Dll before you exit.
    Exit
EndFunc

While 1
    Sleep(1000)
WEnd
Edited by czardas

Share this post


Link to post
Share on other sites
Jack023

Fixed it myself by adding:

        While _IsPressed("20")
            Sleep(100)
        WEnd
 
func say()
    Local $hDLL = DllOpen("user32.dll")
    Send("y")
        $paste = ClipPut("" & $v_array[$i])
        Send("{CTRLDOWN}v{CTRLUP}")
        $i +=1
        If $i = 9 Then $i = 0

    While 1

        If _IsPressed("20", $hDLL) Then
            $paste = ClipPut("" & $v_array[$i])
            Send("{CTRLDOWN}v{CTRLUP}")
            $i +=1
            If $i = 9 Then $i = 0
        While _IsPressed("20")
            Sleep(100)
        WEnd
        EndIf
        If _IsPressed("0D", $hDLL) Then
            DllClose($hDLL) ; Close the Dll before you exit.
            ExitLoop
        EndIf
    WEnd

EndFunc

anyway thanks for helping +1 ^^

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
Sign in to follow this  

×