Sign in to follow this  
Followers 0
Vicate

$d = 0, $d = 1?

12 posts in this topic

#1 ·  Posted (edited)

I apologize for perhaps looking annoying, but this is driving me crazy!

I made a thread about making a script, but I've since made great progress in making it and I'm just having some trouble with this, here.

I figured the thread name would be more specific for this one problem and would warrant more people to try helping me.

I cannot find anything in helpfiles or other scripts that even reference this command.

[code]Func _s()
    $s = PixelGetColor(273, 40)
            $sd = 0
        Switch $s
        Case 0x000000 and $sd = 0
                send("{s down}")
                $sd = 1; <----There's something wrong here, I think.
        Case 0xAAAAAA and $sd = 1
                send("{s up}")
        EndSwitch
endfunc

From what I've heard, if you put the d in front of whatever you're specifying, it sets a condition or something, I don't know.

At the beginning, it sets $sd = 0, no problem, as it follows through with pressing S down.

After that, though, it isn't setting $sd = 1 and I have no clue why, is that written correctly?

I know it isn't setting it because I changed it from

Case 0xAAAAAA and $sd = 1
to
Case 0xAAAAAA and $sd = 0

and it released S, which means it completely ignores $sd = 1.

Any ideas?

Thank you.

Edited by Vicate

Share this post


Link to post
Share on other sites



I know it isn't setting it because I changed it from

Case 0xAAAAAA and $sd = 1
to
Case 0xAAAAAA and $sd = 0

and it released S, which means it completely ignores $sd = 1.

Any ideas?

Thank you.

...and it released S is what i see it should do... 8)

Maybe this can help

Func _s()
    $s = PixelGetColor(273, 40)
    $sd = 0
    Switch $s
        Case 0x000000 And $sd = 0
            Send("{s down}")
            $sd = 1; <----There's something wrong here, I think.
            ConsoleWrite("->" & $sd & @CRLF)
        Case 0xAAAAAA And $sd = 1
            Send("{s up}")
            $sd = 0
            ConsoleWrite("+>" & $sd & @CRLF)
    EndSwitch
EndFunc   ;==>_s

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yeah, I'm trying to get it to release S.

Thanks for responding.

That didn't seem to work, though.

It still holds down the key without releasing.

Really weird :[

Oh yeah, sorry, this also is included, if it helps:

While 1
    _s()
Wend
Edited by Vicate

Share this post


Link to post
Share on other sites

That loop is soooooooo fast, it doesn't have a chance to release the key

try this...

While 1

_s()

Sleep(3000)

Wend


NEWHeader1.png

Share this post


Link to post
Share on other sites

The problem is that select case does NOT let you use multiple expressions like that.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

That loop is soooooooo fast, it doesn't have a chance to release the key

try this...

While 1

_s()

Sleep(3000)

Wend

Well, in its entirety, the script's like this:

CODE
Func _z()

$z = PixelGetColor(270, 55)

$zd = 0

Switch $z

Case 0x000000 and $zd = 0;Color it's looking for when the key is pressed

send("{z down}")

$zd = 1

Case 0xFFFFFF and $zd = 1;Color it's looking for when the key is released

send("{z up}")

EndSwitch

endfunc

Func _s()

$s = PixelGetColor(273, 40)

$sd = 0

Switch $s

Case 0x000000 and $sd = 0;Color it's looking for when the key is pressed

send("{s down}")

$sd = 1

Case 0xADAAAD and $sd = 1;Color it's looking for when the key is released

send("{s up}")

EndSwitch

endfunc

Func _x()

$x = PixelGetColor(279, 55)

$xd = 0

Switch $x

Case 0x000000 and $xd = 0;Color it's looking for when the key is pressed

send("{x down}")

$xd = 1

Case 0xFFFFFF and $xd = 1;Color it's looking for when the key is released

send("{x up}")

EndSwitch

endfunc

Func _d()

$d = PixelGetColor(283, 40)

$dd = 0

Switch $d

Case 0x000000 and $dd = 0;Color it's looking for when the key is pressed

send("{d down}")

$dd = 1

Case 0xADAAAD and $dd = 1;Color it's looking for when the key is released

send("{d up}")

EndSwitch

endfunc

Func _c()

$c = PixelGetColor(288, 55)

$cd = 0

Switch $c

Case 0x000000 and $cd = 0;Color it's looking for when the key is pressed

send("{c down}")

$cd = 1

Case 0xFFFFFF and $cd = 1;Color it's looking for when the key is released

send("{c up}")

EndSwitch

endfunc

Func _v()

$v = PixelGetColor(297, 55)

$vd = 0

Switch $v

Case 0x000000 and $vd = 0;Color it's looking for when the key is pressed

send("{v down}")

$vd = 1

Case 0xFFFFFF and $vd = 1;Color it's looking for when the key is released

send("{v up}")

EndSwitch

endfunc

Func _g()

$g = PixelGetColor(300, 40)

$gd = 0

Switch $g

Case 0x000000 and $gd = 0;Color it's looking for when the key is pressed

send("{g down}")

$gd = 1

Case 0xADAAAD and $gd = 1;Color it's looking for when the key is released

send("{g up}")

EndSwitch

endfunc

Func _b()

$b = PixelGetColor(306, 55)

$bd = 0

Switch $b

Case 0x000000 and $bd = 0;Color it's looking for when the key is pressed

send("{b down}")

$bd = 1

Case 0xFFFFFF and $bd = 1;Color it's looking for when the key is released

send("{b up}")

EndSwitch

endfunc

Func _h()

$h = PixelGetColor(309, 40)

$hd = 0

Switch $h

Case 0x000000 and $hd = 0;Color it's looking for when the key is pressed

send("{h down}")

$hd = 1

Case 0xADAAAD and $hd = 1;Color it's looking for when the key is released

send("{h up}")

EndSwitch

endfunc

Func _n()

$n = PixelGetColor(315, 55)

$nd = 0

Switch $n

Case 0x000000 and $nd = 0;Color it's looking for when the key is pressed

send("{n down}")

$nd = 1

Case 0xFFFFFF and $nd = 1;Color it's looking for when the key is released

send("{n up}")

EndSwitch

endfunc

Func _j()

$j = PixelGetColor(319, 40)

$jd = 0

Switch $j

Case 0x000000 and $jd = 0;Color it's looking for when the key is pressed

send("{j down}")

$jd = 1

Case 0xADAAAD and $jd = 1;Color it's looking for when the key is released

send("{j up}")

EndSwitch

endfunc

Func _m()

$m = PixelGetColor(324, 55)

$md = 0

Switch $m

Case 0x000000 and $md = 0;Color it's looking for when the key is pressed

send("{m down}")

$md = 1

Case 0xFFFFFF and $md = 1;Color it's looking for when the key is released

send("{m up}")

EndSwitch

endfunc

Func _q()

$q = PixelGetColor(333, 55)

$qd = 0

Switch $q

Case 0x000000 and $qd = 0;Color it's looking for when the key is pressed

send("{q down}")

$qd = 1

Case 0xFFFFFF and $qd = 1;Color it's looking for when the key is released

send("{q up}")

EndSwitch

endfunc

Func _2()

$2 = PixelGetColor(336, 40)

$2d = 0

Switch $2

Case 0x000000 and $2d = 0;Color it's looking for when the key is pressed

send("{2 down}")

$2d = 1

Case 0xADAAAD and $2d = 1;Color it's looking for when the key is released

send("{2 up}")

EndSwitch

endfunc

Func _w()

$w = PixelGetColor(342, 55)

$wd = 0

Switch $w

Case 0x000000 and $wd = 0;Color it's looking for when the key is pressed

send("{w down}")

$wd = 1

Case 0xFFFFFF and $wd = 1;Color it's looking for when the key is released

send("{w up}")

EndSwitch

endfunc

Func _3()

$3 = PixelGetColor(346, 40)

$3d = 0

Switch $3

Case 0x000000 and $3d = 0;Color it's looking for when the key is pressed

send("{3 down}")

$3d = 1

Case 0xADAAAD and $3d = 1;Color it's looking for when the key is released

send("{3 up}")

EndSwitch

endfunc

Func _e()

$e = PixelGetColor(350, 55)

$ed = 0

Switch $e

Case 0x000000 and $ed = 0;Color it's looking for when the key is pressed

send("{e down}")

$ed = 1

Case 0xFFFFFF and $ed = 1;Color it's looking for when the key is released

send("{e up}")

EndSwitch

endfunc

Func _r()

$r = PixelGetColor(360, 55)

$rd = 0

Switch $r

Case 0x000000 and $rd = 0;Color it's looking for when the key is pressed

send("{r down}")

$rd = 1

Case 0xFFFFFF and $rd = 1;Color it's looking for when the key is released

send("{r up}")

EndSwitch

endfunc

Func _5()

$5 = PixelGetColor(363, 40)

$5d = 0

Switch $5

Case 0x000000 and $5d = 0;Color it's looking for when the key is pressed

send("{5 down}")

$5d = 1

Case 0xADAAAD and $5d = 1;Color it's looking for when the key is released

send("{5 up}")

EndSwitch

endfunc

Func _t()

$t = PixelGetColor(369, 55)

$td = 0

Switch $t

Case 0x000000 and $td = 0;Color it's looking for when the key is pressed

send("{t down}")

$td = 1

Case 0xFFFFFF and $td = 1;Color it's looking for when the key is released

send("{t up}")

EndSwitch

endfunc

Func _6()

$6 = PixelGetColor(372, 40)

$6d = 0

Switch $6

Case 0x000000 and $6d = 0;Color it's looking for when the key is pressed

send("{6 down}")

$6d = 1

Case 0xADAAAD and $6d = 1;Color it's looking for when the key is released

send("{6 up}")

EndSwitch

endfunc

Func _y()

$y = PixelGetColor(378, 55)

$yd = 0

Switch $y

Case 0x000000 and $yd = 0;Color it's looking for when the key is pressed

send("{y down}")

$yd = 1

Case 0xFFFFFF and $yd = 1;Color it's looking for when the key is released

send("{y up}")

EndSwitch

endfunc

Func _7()

$7 = PixelGetColor(382, 40)

$7d = 0

Switch $7

Case 0x000000 and $7d = 0;Color it's looking for when the key is pressed

send("{7 down}")

$7d = 1

Case 0xADAAAD and $7d = 1;Color it's looking for when the key is released

send("{7 up}")

EndSwitch

endfunc

Func _u()

$u = PixelGetColor(387, 55)

$ud = 0

Switch $u

Case 0x000000 and $ud = 0;Color it's looking for when the key is pressed

send("{u down}")

$ud = 1

Case 0xFFFFFF and $ud = 1;Color it's looking for when the key is released

send("{u up}")

EndSwitch

endfunc

Func _i()

$i = PixelGetColor(396, 55)

$id = 0

Switch $i

Case 0x000000 and $id = 0;Color it's looking for when the key is pressed

send("{i down}")

$id = 1

Case 0xFFFFFF and $id = 1;Color it's looking for when the key is released

send("{i up}")

EndSwitch

endfunc

Func _9()

$9 = PixelGetColor(399, 40)

$9d = 0

Switch $9

Case 0x000000 and $9d = 0;Color it's looking for when the key is pressed

send("{9 down}")

$9d = 1

Case 0xADAAAD and $9d = 1;Color it's looking for when the key is released

send("{9 up}")

EndSwitch

endfunc

Func _o()

$o = PixelGetColor(405, 55)

Switch $o

Case 0x000000 ;Color it's looking for when the key is pressed

send("{o down}")

Case 0xFFFFFF ;Color it's looking for when the key is released

send("{o up}")

EndSwitch

endfunc

Func _0()

$0 = PixelGetColor(409, 40)

$0d = 0

Switch $0

Case 0x000000 and $0d = 0;Color it's looking for when the key is pressed

send("{0 down}")

$0d = 1

Case 0xADAAAD and $0d = 1;Color it's looking for when the key is released

send("{0 up}")

EndSwitch

endfunc

Func _p()

$p = PixelGetColor(414, 55)

$pd = 0

Switch $p

Case 0x000000 and $pd = 0;Color it's looking for when the key is pressed

send("{p down}")

$pd = 1

Case 0xFFFFFF and $pd = 1;Color it's looking for when the key is released

send("{p up}")

EndSwitch

endfunc

Func _brk()

$brk = PixelGetColor(423, 55)

$brkd = 0

Switch $brk

Case 0x000000 and $brkd = 0;Color it's looking for when the key is pressed

send("{[ down}")

$brkd = 1

Case 0xFFFFFF and $brkd = 1;Color it's looking for when the key is released

send("{[ up}")

EndSwitch

endfunc

Func _eq()

$eq = PixelGetColor(426, 40)

$eqd = 0

Switch $eq

Case 0x000000 and $eqd = 0;Color it's looking for when the key is pressed

send("{= down}")

$eqd = 1

Case 0xADAAAD and $eqd = 1;Color it's looking for when the key is released

send("{= up}")

EndSwitch

endfunc

Func _brkc()

$brkc = PixelGetColor(431, 55)

$brkcd = 0

Switch $brkc

Case 0x000000 and $brkcd = 0;Color it's looking for when the key is pressed

send("{] down}")

$brkcd = 1

Case 0xFFFFFF and $brkcd = 1;Color it's looking for when the key is released

send("{] up}")

EndSwitch

endfunc

While 1

_z()

_s()

_x()

_d()

_c()

_v()

_g()

_b()

_h()

_n()

_j()

_m()

_q()

_2()

_w()

_3()

_e()

_r()

_5()

_t()

_6()

_y()

_7()

_u()

_i()

_9()

_o()

_0()

_p()

_brk()

_eq()

_brkc()

Wend

For the sake of not looking repetitive, I only showed $s.

Is that loop still too fast?

It's supposed to be fast, but I don't want it so fast to the point of making it unable to release.

The problem is that select case does NOT let you use multiple expressions like that.

Are you sure? It's sure able to distinguish between

Case 0xFFFFFF and $brkcd = 1 and Case 0xFFFFFF and $brkcd = 0.

It works when $sd = 0 because it doesn't seem to be reading the $sd = 1 prior to it.

It's like it is stuck on $sd = 0.

And if you are correct, what else may I use to achieve a similar output?

Here's what I'm trying to make happen:

It looks for a certain pixel to appear at coordinate xy

If color 0x000000 appears at said coordinate, it sends a keydown, then waits for color 0xFFFFFF to appear at said coordinate.

in which case, it sends the keyup.

Thanks again guys.

Edited by Vicate

Share this post


Link to post
Share on other sites

It's comparing your variable to the result of the true/false AND operation. It's valid but not what you want.

Share this post


Link to post
Share on other sites

It sounds like you need an If...Then statement, with a nested Do...Until loop. Something like this, I think.

If $color1 = 0x00000000 Then
    Do
        Send($key)
    Until $color2 = 0x00FFFFFF
EndIfoÝ÷ Ûú®¢×£*.æ§)¶¬jëh×6Func _5()
$5 = PixelGetColor(363, 40)
    $5d = 0
    If $5 = 0x000000 Then
        $5d = 1
        Do
            Send("{5 down}")
        Until $5 = 0xADAAAD
    EndIf
    If $5 = 0xADAAAD  And $5d = 1 Then
        $5d = 0
        Send("{5 up}")
    EndIf
EndFunc
While 1
    _5()
WEnd

Still, it doesn't initiate a "button up" to be sent.

Even when I put the Sleep(3000) on the loop, no release :[

Share this post


Link to post
Share on other sites

For one thing (in your original code) $zd gets set to 1 and just stays there. You forgot to reset it after the send("{z up}") and I would assume that you don't want that because your first Case statement will never match again and the second won't match unless the color is correct but then all it's doing is repeating send("{z up}") which would already be the state of that key because it matched the first time.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

...and it released S is what i see it should do... 8)

Maybe this can help

Func _s()
    $s = PixelGetColor(273, 40)
    $sd = 0
    Switch $s
        Case 0x000000 And $sd = 0
            Send("{s down}")
            $sd = 1; <----There's something wrong here, I think.
            ConsoleWrite("->" & $sd & @CRLF)
        Case 0xAAAAAA And $sd = 1
            Send("{s up}")
            $sd = 0
            ConsoleWrite("+>" & $sd & @CRLF)
    EndSwitch
EndFunc   ;==>_s

8)

Valuater ? is that really you?? I think you have been Switched for an alien but why did they Select you?

Select
        Case $s =0x000000 And $sd = 0
            Send("{s down}")
            $sd = 1; <----There's something wrong here, I think.
            ConsoleWrite("->" & $sd & @CRLF)
        Case $s = 0xAAAAAA And $sd = 1
            Send("{s up}")
            $sd = 0
            ConsoleWrite("+>" & $sd & @CRLF)
    EndSelect

I think we should pay the ransom :D


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Select
        Case $s =0x000000 And $sd = 0
            Send("{s down}")
            $sd = 1; <----There's something wrong here, I think.
            ConsoleWrite("->" & $sd & @CRLF)
        Case $s = 0xAAAAAA And $sd = 1
            Send("{s up}")
            $sd = 0
            ConsoleWrite("+>" & $sd & @CRLF)
    EndSelect
Alright, so:

Func _5()
    $5 = PixelGetColor(363, 40)
    $5d = 0
Select
        Case $5 =0x000000 And $5d = 0
            Send("{5 down}")
            $5d = 1
            ConsoleWrite("->" & $5d & @CRLF)
        Case $5 = 0xADAAAD And $5d = 1
            Send("{5 up}")
            $5d = 0
            ConsoleWrite("+>" & $sd & @CRLF)
        EndSelect
EndFunc
   
While 1
    _5()
WEndoÝ÷ Ù8b²ÞêÞÉ÷ö×èZ0x-º."¶ay»­¶ëzW±ê®¢×§jg

This works, however when 0x000000 appears at both the $5 coordinate and the $y coordinate, I would like it to simultaneously press both down, which it isn't doing.

It's hitting either one or the other.

Also, is that constantly sending the keyup commands, or is it only coming up once the key has been pressed down?

Mind you that I have 32 of these going on, so constantly sending near-32 redundant keyup commands would seem to pre-occupy it, but that's just a guess on my part.

Share this post


Link to post
Share on other sites

Alright, I've figured something that works great.

Now I've just got to fiddle with getting it to work with a GUI...

How do you apply it to a GUI?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
$dll = DllOpen("user32.dll")

#Region ### 
$Form1_1 = GUICreate("Title", 116, 212, 448, 181)
GUISetFont(8, 400, 0, "Arial")
GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup("Player", 8, 144, 97, 41)
GUICtrlSetColor(-1, 0xC0C0C0)
$On = GUICtrlCreateButton("On", 12, 160, 41, 17, $WS_GROUP)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
$Off = GUICtrlCreateButton("Off", 55, 160, 41, 17, $WS_GROUP)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$noplaying = GUICtrlCreatePic("img.gif", 8, 8, 98, 129, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Info = GUICtrlCreateButton("Info", 36, 186, 41, 17, $WS_GROUP)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Func _5()
    $5 = PixelGetColor(363, 40)
        Select
        Case $5 = 0x000000
                send("{5 down}")
        Case $5 <> 0x000000 And _IsPressed("35", $dll)
                send("{5 up}")
        EndSelect
    EndFunc
    
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Info
            ;When this is pressed, I want a window to pop up that I can put info
        Case $On
            ;When this is pressed, I want it to "activate" Func_5
            ;And perhaps turn the button color to orange or something to indicate that it is on.
            ;If the Off Button was on, I'd want the Off Button to return to its original color.
        Case $Off
            ;When this is pressed, I want it to "deactivate" Func_5
            ;And perhaps turn the button color to orange or something to indicate that it is off.
            ;If the On Button was on, I'd want the On Button to return to its original color.
    EndSwitch
WEnd

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  
Followers 0