Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

If statment needs help

Hello all and thank you for reading this post. Below is a code snipet from my program.
On the bottom of the window is a solid black bar.
When a message window is opened and then minimized it creates a tab on this black bar (the tab is NOT black)

I want to know how to determin when the bar is not nlack and send a mouseclick on that tab (more tabs will move, most recent tab will be first)

Here is the code I have but I cannot seem to get it to work.
Can someone look at the code and tell me how to fix it (clean it up) to where it will work as it should.
Thank you

[code]AU3_MouseMove (280,730,1);
Spambox:=AU3_PixelGetColor (280,730);
if Spambox=0 then
begin
AU3_MouseMove (380,730,1);
Spambox:=AU3_PixelGetColor (380,730);
end;
if Spambox=0 then
begin
AU3_MouseMove (480,730,1);
Spambox:=AU3_PixelGetColor (480,730);
end;
if Spambox=0 then
begin
AU3_MouseMove (580,730,1);
Spambox:=AU3_PixelGetColor (580,730);
end;
if Spambox=0 then
begin
AU3_MouseMove (680,730,1);
Spambox:=AU3_PixelGetColor (680,730);
end;
if Spambox=0 then
begin
AU3_MouseMove (780,730,1);
Spambox:=AU3_PixelGetColor (780,730);
end;
if Spambox=0 then
begin
AU3_MouseMove (880,730,1);
Spambox:=AU3_PixelGetColor (880,730);
end
else if Spambox<>0 then
begin
AU3_MouseDown ('left');
end;
Sleep (1000);
AU3_MouseClick ('left', 137,367, 1, 3);
AU3_Send (spamsg2,0);
AU3_Send ('{ENTER}',0);
Sleep (1000);
Sleep (300000);[/code]

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello all and thank you for reading this post. Below is a code
    : snipet from my program.
    : On the bottom of the window is a solid black bar.
    : When a message window is opened and then minimized it creates a tab
    : on this black bar (the tab is NOT black)
    :
    : I want to know how to determin when the bar is not nlack and send a
    : mouseclick on that tab (more tabs will move, most recent tab will be
    : first)
    :
    : Here is the code I have but I cannot seem to get it to work.
    : Can someone look at the code and tell me how to fix it (clean it up)
    : to where it will work as it should.
    : Thank you
    :
    : [code]: AU3_MouseMove (280,730,1);
    : Spambox:=AU3_PixelGetColor (280,730);
    : if Spambox=0 then
    : begin
    : AU3_MouseMove (380,730,1);
    : Spambox:=AU3_PixelGetColor (380,730);
    : end;
    : if Spambox=0 then
    : begin
    : AU3_MouseMove (480,730,1);
    : Spambox:=AU3_PixelGetColor (480,730);
    : end;
    : if Spambox=0 then
    : begin
    : AU3_MouseMove (580,730,1);
    : Spambox:=AU3_PixelGetColor (580,730);
    : end;
    : if Spambox=0 then
    : begin
    : AU3_MouseMove (680,730,1);
    : Spambox:=AU3_PixelGetColor (680,730);
    : end;
    : if Spambox=0 then
    : begin
    : AU3_MouseMove (780,730,1);
    : Spambox:=AU3_PixelGetColor (780,730);
    : end;
    : if Spambox=0 then
    : begin
    : AU3_MouseMove (880,730,1);
    : Spambox:=AU3_PixelGetColor (880,730);
    : end
    : else if Spambox<>0 then
    : begin
    : AU3_MouseDown ('left');
    : end;
    : Sleep (1000);
    : AU3_MouseClick ('left', 137,367, 1, 3);
    : AU3_Send (spamsg2,0);
    : AU3_Send ('{ENTER}',0);
    : Sleep (1000);
    : Sleep (300000);[/code]:
    :
    All those if-then statements are looked at in sequence, and are not nested or part of an if-then-else chain. Here's a code which looks at the various locations in sequence:
    [code]
    i := 0;
    Spambox := 0;
    while Spambox = 0 do
    begin
    case i of
    0: begin
    AU3_MouseMove (280,730,1);
    Spambox := AU3_PixelGetColor (280,730);
    end;
    1: begin
    AU3_MouseMove (380,730,1);
    Spambox:=AU3_PixelGetColor (380,730);
    end;
    2: begin
    AU3_MouseMove (480,730,1);
    Spambox:=AU3_PixelGetColor (480,730);
    end;
    3: begin
    AU3_MouseMove (580,730,1);
    Spambox:=AU3_PixelGetColor (580,730);
    end;
    4: begin
    AU3_MouseMove (680,730,1);
    Spambox:=AU3_PixelGetColor (680,730);
    end;
    5: begin
    AU3_MouseMove (780,730,1);
    Spambox:=AU3_PixelGetColor (780,730);
    end;
    6: begin
    AU3_MouseMove (880,730,1);
    Spambox:=AU3_PixelGetColor (880,730);
    end;
    7: break;
    end;
    inc(i);
    end;
    if Spambox<>0 then
    begin
    AU3_MouseDown ('left');
    end;
    [/code]
  • caspert_ghostcaspert_ghost Member Posts: 53
    : All those if-then statements are looked at in sequence, and are not
    : nested or part of an if-then-else chain. Here's a code which looks
    : at the various locations in sequence:
    : [code]:
    : i := 0;
    : Spambox := 0;
    : while Spambox = 0 do
    : begin
    : case i of
    : 0: begin
    : AU3_MouseMove (280,730,1);
    : Spambox := AU3_PixelGetColor (280,730);
    : end;
    : 1: begin
    : AU3_MouseMove (380,730,1);
    : Spambox:=AU3_PixelGetColor (380,730);
    : end;
    : 2: begin
    : AU3_MouseMove (480,730,1);
    : Spambox:=AU3_PixelGetColor (480,730);
    : end;
    : 3: begin
    : AU3_MouseMove (580,730,1);
    : Spambox:=AU3_PixelGetColor (580,730);
    : end;
    : 4: begin
    : AU3_MouseMove (680,730,1);
    : Spambox:=AU3_PixelGetColor (680,730);
    : end;
    : 5: begin
    : AU3_MouseMove (780,730,1);
    : Spambox:=AU3_PixelGetColor (780,730);
    : end;
    : 6: begin
    : AU3_MouseMove (880,730,1);
    : Spambox:=AU3_PixelGetColor (880,730);
    : end;
    : 7: break;
    : end;
    : inc(i);
    : end;
    : if Spambox<>0 then
    : begin
    : AU3_MouseDown ('left');
    : end;
    : [/code]:

    Thank you, but its still not working. I will include the entire funtion code this time, maybe I missed something.

    This is a TTimer that goes off every 5 mins (but resolves every 15 mins)
    ((meaning it goes off does one section of code sleeps 5 mins does 2nd section sleeps 5 mins then does final section and restarts after 5 mins))

    [code]procedure Tcontrol_panel.TimerSpam1Timer(Sender: TObject);
    // 5 min spam cycle
    var
    spamsg1, spamsg2, spamsg3:string;
    Spambox, i:integer;
    begin
    inifile:=Tinifile.Create('./OH_BOT.ini');
    spamsg1:=inifile.ReadString('Spam','Message1','');
    spamsg2:=inifile.ReadString('Spam','Message2','');
    spamsg3:=inifile.ReadString('Spam','Message3','');
    repeat coord:=AU3_PixelGetColor (822,704);
    Sleep (5000);
    until
    (coord<>9802661);
    i:= 0;
    Spambox := 0;
    while Spambox = 0 do
    begin
    case i of
    0:begin
    AU3_MouseMove (280,730,1);
    Spambox:=AU3_PixelGetColor (280,730);
    end;
    1:begin
    AU3_MouseMove (380,730,1);
    Spambox:=AU3_PixelGetColor (380,730);
    end;
    2:begin
    AU3_MouseMove (480,730,1);
    Spambox:=AU3_PixelGetColor (480,730);
    end;
    3:begin
    AU3_MouseMove (580,730,1);
    Spambox:=AU3_PixelGetColor (580,730);
    end;
    4:begin
    AU3_MouseMove (680,730,1);
    Spambox:=AU3_PixelGetColor (680,730);
    end;
    5:begin
    AU3_MouseMove (780,730,1);
    Spambox:=AU3_PixelGetColor (780,730);
    end;
    6:begin
    AU3_MouseMove (880,730,1);
    Spambox:=AU3_PixelGetColor (880,730);
    end;
    7:break;
    end;
    inc(i);
    if Spambox<>0 then
    begin
    AU3_MouseDown ('left');
    Sleep(1000);
    end;
    AU3_MouseClick('left', 137, 367, 1, 3);
    AU3_Send('spamsg2', 0);
    AU3_Send('{ENTER}', 0);
    Sleep(1000);
    Sleep (300000);
    repeat coord:=AU3_PixelGetColor (822,704);
    Sleep (5000);
    until
    (coord<>9802661);
    i:= 0;
    Spambox := 0;
    while Spambox = 0 do
    begin
    case i of
    0:begin
    AU3_MouseMove (280,730,1);
    Spambox:=AU3_PixelGetColor (280,730);
    end;
    1:begin
    AU3_MouseMove (380,730,1);
    Spambox:=AU3_PixelGetColor (380,730);
    end;
    2:begin
    AU3_MouseMove (480,730,1);
    Spambox:=AU3_PixelGetColor (480,730);
    end;
    3:begin
    AU3_MouseMove (580,730,1);
    Spambox:=AU3_PixelGetColor (580,730);
    end;
    4:begin
    AU3_MouseMove (680,730,1);
    Spambox:=AU3_PixelGetColor (680,730);
    end;
    5:begin
    AU3_MouseMove (780,730,1);
    Spambox:=AU3_PixelGetColor (780,730);
    end;
    6:begin
    AU3_MouseMove (880,730,1);
    Spambox:=AU3_PixelGetColor (880,730);
    end;
    7:break;
    end;
    inc(i);
    if Spambox<>0 then
    begin
    AU3_MouseDown ('left');
    Sleep(1000);
    end;
    AU3_MouseClick ('left', 137,367, 1, 3);
    AU3_Send (spamsg3,0);
    AU3_Send ('{ENTER}',0);
    Sleep (300000);
    repeat coord:=AU3_PixelGetColor (822,704);
    Sleep (5000);
    until
    (coord<>9802661);
    i:= 0;
    Spambox := 0;
    while Spambox = 0 do
    begin
    case i of
    0:begin
    AU3_MouseMove (280,730,1);
    Spambox:=AU3_PixelGetColor (280,730);
    end;
    1:begin
    AU3_MouseMove (380,730,1);
    Spambox:=AU3_PixelGetColor (380,730);
    end;
    2:begin
    AU3_MouseMove (480,730,1);
    Spambox:=AU3_PixelGetColor (480,730);
    end;
    3:begin
    AU3_MouseMove (580,730,1);
    Spambox:=AU3_PixelGetColor (580,730);
    end;
    4:begin
    AU3_MouseMove (680,730,1);
    Spambox:=AU3_PixelGetColor (680,730);
    end;
    5:begin
    AU3_MouseMove (780,730,1);
    Spambox:=AU3_PixelGetColor (780,730);
    end;
    6:begin
    AU3_MouseMove (880,730,1);
    Spambox:=AU3_PixelGetColor (880,730);
    end;
    7:break;
    end;
    inc(i);
    if Spambox<>0 then
    begin
    AU3_MouseDown ('left');
    Sleep(1000);
    end;
    AU3_MouseClick ('left', 137,367, 1, 3);
    AU3_Send (spamsg1,0);
    AU3_Send ('{ENTER}',0);
    end;
    end;
    [/code]

    Thank you
    OR simplify it and search the bar UNTIL it is NOT black and click that spot, then continue with remainder of code.
  • zibadianzibadian Member Posts: 6,349
    : : All those if-then statements are looked at in sequence, and are not
    : : nested or part of an if-then-else chain. Here's a code which looks
    : : at the various locations in sequence:

    : Thank you, but its still not working. I will include the entire
    : funtion code this time, maybe I missed something.
    :
    : This is a TTimer that goes off every 5 mins (but resolves every 15
    : mins)
    : ((meaning it goes off does one section of code sleeps 5 mins does
    : 2nd section sleeps 5 mins then does final section and restarts after
    : 5 mins))
    :
    : Thank you
    : OR simplify it and search the bar UNTIL it is NOT black and click
    : that spot, then continue with remainder of code.

    Here is a new code, which does the same thing, but is much easier to debug.
    [code]
    procedure TControl_Panel.TimerSpam1Timer(Sender: TObject);
    const
    GetPixelX: array[0..6] = (280, 380, 480, 580, 680, 780, 880);
    GetPixelY = 730;
    var
    SpamMsg: string;
    MessageID, SpamIndex, SpamBox: integer;
    begin
    inifile:=Tinifile.Create('./OH_BOT.ini');
    try
    for MessageID := 1 to 3 do
    begin
    SpamMsg:=inifile.ReadString('Spam','Message'+IntToStr(MessageID),'');
    repeat
    coord := AU3_PixelGetColor (822,704);
    Sleep(5000);
    until (coord <> 9802661); [red]// What's this for a magic number?[/red]
    for SpamIndex := 0 to 6 do
    begin
    AU3_MouseMove(GetPixelX[SpamIndex], GetPixelY, 1);
    Spambox := AU3_PixelGetColor(GetPixelX[SpamIndex], GetPixelY);
    if SpamBox <> 0 then
    begin
    AU3_MouseDown('left');
    Sleep(1000);
    Break;
    end;
    end;
    AU3_MouseClick('left', 137, 367, 1, 3);
    AU3_Send('spamsg2', 0);
    AU3_Send('{ENTER}', 0);
    Sleep(1000);
    Sleep (300000); [red]// why this sleep?[/red]
    repeat
    coord:=AU3_PixelGetColor (822,704);
    Sleep (5000);
    until (coord<>9802661); [red]// What's this for a magic number?[/red]
    end;
    finally
    inifile.Free;
    end;
    end;
    [/code]
    Your code had a lot of indentation error, which make it very difficult to read the flow of the program. In the official Delphi layout, every end must be on the same indentation as it's accompanying begin/case/class/procedure/record line.
    Assuming sleep() is a blocking wait, all those Sleep() statements, make larger than 5 minutes, thus making the timer unnecessary. If they are non-blocking, then you have a world of trouble, because then this code becomes multithreaded without synchonization.
    You also forgot to free the inifile(), which is a memory leak.
    Also beware of hard coding locations/colors, etc. Especially if you're going to use them in multiple places. Just make it a descriptive constant (see code above) and use that instead. This will also improve the readability of your code and makes it easier to alter it later on.
    Finally if you have repeating code, then it is often better to either make a function/procedure which performs that code, or make it a loop (like I did here). If the code doesn't work, you only need to change 1 statement and not a large number.

    My remarks may seem harsh, but they are meant to help you become a better programmer and make your programs easier to read, debug and maintain.
  • caspert_ghostcaspert_ghost Member Posts: 53
    : Here is a new code, which does the same thing, but is much easier to
    : debug.
    : [code]:
    : procedure TControl_Panel.TimerSpam1Timer(Sender: TObject);
    : const
    : GetPixelX: array[0..6] = (280, 380, 480, 580, 680, 780, 880);
    : GetPixelY = 730;
    : var
    : SpamMsg: string;: MessageID, SpamIndex, SpamBox: integer;
    : begin
    : inifile:=Tinifile.Create('./OH_BOT.ini');
    : try
    : for MessageID := 1 to 3 do
    : begin
    : SpamMsg:=inifile.ReadString('Spam','Message'+IntToStr(MessageID),'');
    : repeat
    : coord := AU3_PixelGetColor (822,704);
    : Sleep(5000);
    : until (coord <> 9802661); [red]// What's this for a magic number?[/red] [color=Purple]This particular loop is
    IF the program is IN a trade it will NOT send the "spam" message until it has finished the trade. [/color]
    : for SpamIndex := 0 to 6 do
    : begin
    : AU3_MouseMove(GetPixelX[SpamIndex], GetPixelY, 1);
    : Spambox := AU3_PixelGetColor(GetPixelX[SpamIndex], GetPixelY);
    : if SpamBox <> 0 then
    : begin
    : AU3_MouseDown('left');
    : Sleep(1000);
    : Break;
    : end;
    : end;
    : AU3_MouseClick('left', 137, 367, 1, 3);
    : AU3_Send('spamsg2', 0);[color=Purple]// this is message 2, how does it know to send message 1 and message 3?[/color]
    : AU3_Send('{ENTER}', 0);
    : Sleep(1000);
    : Sleep (300000); [red]// why this sleep?[/red][color=Purple]This is a 5 mion sleep before it sends the 2nd message,
    I used this because we can not "pause" the timer per say so I put all 3 messages on a
    single timer with a sleep in between.[/color]
    : repeat
    : coord:=AU3_PixelGetColor (822,704);
    : Sleep (5000);
    : until (coord<>9802661); [red]// What's this for a magic number?[/red][color=Purple]Again this is waiting for NO trade,
    if no trade then this actually skips as 9802661 is the color of the chat box in the trade room[/color]
    : end;
    : finally
    : inifile.Free;
    : end;
    : end;
    : [/code]:
    : Your code had a lot of indentation error, which make it very
    : difficult to read the flow of the program. In the official Delphi
    : layout, every end must be on the same indentation as it's
    : accompanying begin/case/class/procedure/record line.
    : Assuming sleep() is a blocking wait, all those Sleep() statements,
    : make larger than 5 minutes, thus making the timer unnecessary. If
    : they are non-blocking, then you have a world of trouble, because
    : then this code becomes multithreaded without synchonization.
    : You also forgot to free the inifile(), which is a memory leak.
    : Also beware of hard coding locations/colors, etc. Especially if
    : you're going to use them in multiple places. Just make it a
    : descriptive constant (see code above) and use that instead. This
    : will also improve the readability of your code and makes it easier
    : to alter it later on.
    : Finally if you have repeating code, then it is often better to
    : either make a function/procedure which performs that code, or make
    : it a loop (like I did here). If the code doesn't work, you only need
    : to change 1 statement and not a large number.
    :
    : My remarks may seem harsh, but they are meant to help you become a
    : better programmer and make your programs easier to read, debug and
    : maintain.

    I made notes in your quote in purple. What would you recomend I use rather than sleep for 5 mins? the code loops 15 mins the 5 mins and runs again. I did this otherwise I would end up with 3 different timers all doing the same thing.

    GetPixelX: array[0..6] [color=Red]=[/color] (280[color=Red],[/color] 380, 480, 580, 680, 780, 880); [color=Red][Pascal Error] Bot.pas(720): E2029 'OF' expected but '=' found...[Pascal Error] Bot.pas(720): E2029 ')' expected but ',' found[/color]


    Not sure if it is important or not but I am using Turbo Delphi (I have learned some code from Delphi 7 wont work in Turbo Delphi.)
  • zibadianzibadian Member Posts: 6,349
    : : Here is a new code, which does the same thing, but is much easier to
    : : debug.
    : : [code]: :
    : : procedure TControl_Panel.TimerSpam1Timer(Sender: TObject);
    : : const
    : : GetPixelX: array[0..6] = (280, 380, 480, 580, 680, 780, 880);
    : : GetPixelY = 730;
    : : var
    : : SpamMsg: string;: MessageID, SpamIndex, SpamBox: integer;
    : : begin
    : : inifile:=Tinifile.Create('./OH_BOT.ini');
    : : try
    : : for MessageID := 1 to 3 do
    : : begin
    : : SpamMsg:=inifile.ReadString('Spam','Message'+IntToStr(MessageID),'');
    : : repeat
    : : coord := AU3_PixelGetColor (822,704);
    : : Sleep(5000);
    : : until (coord <> 9802661); [red]// What's this for a magic number?[/red] [color=Purple]This particular loop is
    : IF the program is IN a trade it will NOT send the "spam" message until it has finished the trade. [/color]
    : : for SpamIndex := 0 to 6 do
    : : begin
    : : AU3_MouseMove(GetPixelX[SpamIndex], GetPixelY, 1);
    : : Spambox := AU3_PixelGetColor(GetPixelX[SpamIndex], GetPixelY);
    : : if SpamBox <> 0 then
    : : begin
    : : AU3_MouseDown('left');
    : : Sleep(1000);
    : : Break;
    : : end;
    : : end;
    : : AU3_MouseClick('left', 137, 367, 1, 3);
    : : AU3_Send('spamsg2', 0);[color=Purple]// this is message 2, how does it know to send message 1 and message 3?[/color]
    : : AU3_Send('{ENTER}', 0);
    : : Sleep(1000);
    : : Sleep (300000); [red]// why this sleep?[/red][color=Purple]This is a 5 mion sleep before it sends the 2nd message,
    : I used this because we can not "pause" the timer per say so I put all 3 messages on a
    : single timer with a sleep in between.[/color]
    : : repeat
    : : coord:=AU3_PixelGetColor (822,704);
    : : Sleep (5000);
    : : until (coord<>9802661); [red]// What's this for a magic number?[/red][color=Purple]Again this is waiting for NO trade,
    : if no trade then this actually skips as 9802661 is the color of the chat box in the trade room[/color]
    : : end;
    : : finally
    : : inifile.Free;
    : : end;
    : : end;
    : : [/code]: :
    : : Your code had a lot of indentation error, which make it very
    : : difficult to read the flow of the program. In the official Delphi
    : : layout, every end must be on the same indentation as it's
    : : accompanying begin/case/class/procedure/record line.
    : : Assuming sleep() is a blocking wait, all those Sleep() statements,
    : : make larger than 5 minutes, thus making the timer unnecessary. If
    : : they are non-blocking, then you have a world of trouble, because
    : : then this code becomes multithreaded without synchonization.
    : : You also forgot to free the inifile(), which is a memory leak.
    : : Also beware of hard coding locations/colors, etc. Especially if
    : : you're going to use them in multiple places. Just make it a
    : : descriptive constant (see code above) and use that instead. This
    : : will also improve the readability of your code and makes it easier
    : : to alter it later on.
    : : Finally if you have repeating code, then it is often better to
    : : either make a function/procedure which performs that code, or make
    : : it a loop (like I did here). If the code doesn't work, you only need
    : : to change 1 statement and not a large number.
    : :
    : : My remarks may seem harsh, but they are meant to help you become a
    : : better programmer and make your programs easier to read, debug and
    : : maintain.
    :
    : I made notes in your quote in purple. What would you recomend I use
    : rather than sleep for 5 mins? the code loops 15 mins the 5 mins and
    : runs again. I did this otherwise I would end up with 3 different
    : timers all doing the same thing.
    :
    : GetPixelX: array[0..6] [color=Red]=[/color] (280[color=Red],[/color]
    : 380, 480, 580, 680, 780, 880); [color=Red][Pascal Error]
    : Bot.pas(720): E2029 'OF' expected but '=' found...[Pascal Error]
    : Bot.pas(720): E2029 ')' expected but ',' found[/color]
    :
    :
    : Not sure if it is important or not but I am using Turbo Delphi (I
    : have learned some code from Delphi 7 wont work in Turbo Delphi.)

    Sorry I made an error there:
    [code]
    GetPixelX: array[0..6] of integer = ();
    [/code]
    This construct has been around since at least Turbo Pascal 5, probably longer. It is simply a constant array.
  • caspert_ghostcaspert_ghost Member Posts: 53
    Getting closer, Thank you very much Z.
    [code]procedure Tcontrol_panel.TimerSpam1Timer(Sender: TObject);
    const
    GetPixelX: array[0..6] of integer = (280, 380, 480, 580, 680, 780, 880);
    GetPixelY = 730;
    var
    SpamMsg: string;
    MessageID, SpamIndex, SpamBox: integer;
    begin
    inifile:=Tinifile.Create('./OH_BOT.ini');
    repeat
    coord := AU3_PixelGetColor (822,704);
    Sleep(5000);
    until (coord <> 9802661);

    try
    for MessageID := 1 to 3 do
    begin
    SpamMsg:=inifile.ReadString('Spam','Message'+IntToStr(MessageID),'');
    for SpamIndex := 0 to 6 do
    begin
    AU3_MouseMove(GetPixelX[SpamIndex], GetPixelY, 1);
    Spambox:= AU3_PixelGetColor(GetPixelX[SpamIndex], GetPixelY);
    if SpamBox <> 0 then
    begin
    AU3_MouseDown('left');
    Sleep(1000);
    Break;
    end;
    end;[color=Red]click on first tab THEN send below code[/color]
    AU3_MouseClick('left', 137, 367, 1, 3);
    AU3_Send(SpamMsg, 0);
    AU3_Send('{ENTER}', 0);
    Sleep(1000);
    end;
    finally
    inifile.Free;
    end;
    end;
    [/code]

    However now it clicks on the first tab, then the 2nd, tab, so on... I ONLY want it to click on the first tab then do the AU3_Send(SpamMsg, 0);
    it clicked on each button AND did not send the message. (it opened all the tabs I have on the bottom)
    Also there are 3 messages it needs to send (message 2 first, wait 5 mins and msg 3 during the 2nd cycle, and message 1 during the 3rd cycle and back to message 2 on the 4th cycle so on so on...)


  • zibadianzibadian Member Posts: 6,349
    : Getting closer, Thank you very much Z.
    : [code]: procedure Tcontrol_panel.TimerSpam1Timer(Sender: TObject);
    : const
    : GetPixelX: array[0..6] of integer = (280, 380, 480, 580, 680, 780, 880);
    : GetPixelY = 730;
    : var
    : SpamMsg: string;
    : MessageID, SpamIndex, SpamBox: integer;
    : begin
    : inifile:=Tinifile.Create('./OH_BOT.ini');
    : repeat
    : coord := AU3_PixelGetColor (822,704);
    : Sleep(5000);
    : until (coord <> 9802661);
    :
    : try
    : [blue]for MessageID := 1 to 3 do[/blue]
    : begin
    : [blue]SpamMsg:=inifile.ReadString('Spam','Message'+IntToStr(MessageID),'');[/blue]
    : for SpamIndex := 0 to 6 do
    : begin
    : AU3_MouseMove(GetPixelX[SpamIndex], GetPixelY, 1);
    : Spambox:= AU3_PixelGetColor(GetPixelX[SpamIndex], GetPixelY);
    : if SpamBox <> 0 then
    : begin
    : AU3_MouseDown('left');
    : Sleep(1000);
    : Break;
    : end;
    : end;[color=Red]move this end to include the code below[/color]
    : AU3_MouseClick('left', 137, 367, 1, 3);
    : [/blue]AU3_Send(SpamMsg, 0);[/blue]
    : AU3_Send('{ENTER}', 0);
    : Sleep(1000);
    : end;
    : finally
    : inifile.Free;
    : end;
    : end;
    : [/code]:
    :
    : However now it clicks on the first tab, then the 2nd, tab, so on...
    : I ONLY want it to click on the first tab then do the
    : AU3_Send(SpamMsg, 0);
    : it clicked on each button AND did not send the message. (it opened
    : all the tabs I have on the bottom)
    : Also there are 3 messages it needs to send (message 2 first, wait 5
    : mins and msg 3 during the 2nd cycle, and message 1 during the 3rd
    : cycle and back to message 2 on the 4th cycle so on so on...)
    :
    That's what the for-MessageID is for. Instead of copying the code 3 times and changing a several constants, I surrounded the entire code with a for loop, which counts the number of messages.
    Here's the code if you want the timer to make the 5 minute wait:
    [code]
    procedure Tcontrol_panel.TimerSpam1Timer(Sender: TObject);
    const
    GetPixelX: array[0..6] of integer = (280, 380, 480, 580, 680, 780, 880);
    GetPixelY = 730;
    var
    SpamMsg: string;
    MessageID, SpamIndex, SpamBox: integer;
    begin
    inifile:=Tinifile.Create('./OH_BOT.ini');
    repeat
    coord := AU3_PixelGetColor (822,704);
    Sleep(5000);
    until (coord <> 9802661);

    try
    if (TimerSpam1.Tag < 1) or (TimerSpam1.Tag > 3) then
    TimerSpam1.Tag := 1; // Safety to make sure that illegal values for the message index are filtered out.
    SpamMsg:=inifile.ReadString('Spam','Message'+IntToStr(TimerSpam1.Tag),'');
    for SpamIndex := 0 to 6 do
    begin
    AU3_MouseMove(GetPixelX[SpamIndex], GetPixelY, 1);
    Spambox := AU3_PixelGetColor(GetPixelX[SpamIndex], GetPixelY);
    AU3_MouseDown('left');
    Sleep(1000);
    AU3_MouseClick('left', 137, 367, 1, 3);
    AU3_Send(SpamMsg, 0);
    AU3_Send('{ENTER}', 0);
    Sleep(1000);
    end;
    end;
    TimerSpam1.Tag := (TimerSpam1.Tag+1) mod 3+1;
    finally
    inifile.Free;
    end;
    end;
    [/code]
    This code uses the TimerSpam1.Tag property to store the message index in. I hope, I've also fixed the tab clicking. It now clicks each tab, then clicks somewhere else and sends the message, and repeats that 6 more times.
  • caspert_ghostcaspert_ghost Member Posts: 53
    I got this code to work:
    [code]const
    GetPixelX: array[0..6] of integer = (280, 380, 480, 580, 680, 780, 880);
    GetPixelY = 730;
    var
    SpamMsg: string;
    MessageID, SpamIndex, SpamBox: integer;
    begin
    inifile:=Tinifile.Create('./OH_BOT.ini');
    repeat
    coord := AU3_PixelGetColor (822,704);
    Sleep(5000);
    until (coord <> 9802661);

    try
    if (TimerSpam1.Tag < 1) or (TimerSpam1.Tag > 3) then
    TimerSpam1.Tag := 1; // Safety to make sure that illegal values for the message index are filtered out.
    SpamMsg:=inifile.ReadString('Spam','Message'+IntToStr(TimerSpam1.Tag),'');
    for SpamIndex:= 0 to 6 do
    begin
    AU3_MouseMove(GetPixelX[SpamIndex], GetPixelY, 1);
    Spambox:= AU3_PixelGetColor(GetPixelX[SpamIndex], GetPixelY);
    if SpamBox <> 0 then
    begin
    AU3_MouseDown('left');
    Sleep(1000);
    Break;
    end;
    end;
    AU3_MouseClick('left', 137, 367, 1, 3);
    AU3_Send(SpamMsg, 0);
    AU3_Send('{ENTER}', 0);
    Sleep(1000);
    AU3_MouseClick ('left', 684,149,1,3);
    finally
    TimerSpam1.Tag := (TimerSpam1.Tag+1) mod 3+1;
    inifile.Free;
    end;
    end;[/code]

    However it is opening the tab and not doing the sleep in between open and click (to activate box) and then minimizing again (not sending the message as it is going too fast)
  • caspert_ghostcaspert_ghost Member Posts: 53
    This is what I ended up with. Thank you so very much for your help on this Z

    [code]// 5 min spam cycle
    const
    GetPixelX: array[0..6] of integer = (280, 380, 480, 580, 680, 780, 880);
    GetPixelY = 730;
    var
    SpamMsg: string;
    MessageID, SpamIndex, SpamBox: integer;
    begin
    inifile:=Tinifile.Create('./OH_BOT.ini');
    repeat
    coord := AU3_PixelGetColor (822,704);
    Sleep(5000);
    until (coord <> 9802661);

    try
    if (TimerSpam1.Tag < 1) or (TimerSpam1.Tag > 3) then
    TimerSpam1.Tag := 2; // Safety to make sure that illegal values for the message index are filtered out.
    SpamMsg:=inifile.ReadString('Spam','Message'+IntToStr(TimerSpam1.Tag),'');
    for SpamIndex:= 0 to 6 do
    begin
    AU3_MouseMove(GetPixelX[SpamIndex], GetPixelY, 1);
    Spambox:= AU3_PixelGetColor(GetPixelX[SpamIndex], GetPixelY);
    if SpamBox <> 0 then
    begin
    AU3_MouseDown('left');
    AU3_MouseClick('left', 137, 367, 1, 3);
    Break;
    end;
    end;
    Sleep(1000);
    AU3_MouseClick('left', 140, 367, 1, 3);
    Clipboard.Astext:=SpamMsg;
    AU3_Send ('{CTRLDOWN}v{CTRLUP}',0);
    Sleep(1000);
    AU3_Send('{ENTER}', 0);
    Sleep(1000);
    AU3_MouseClick ('left', 684,149,1,3);
    finally
    TimerSpam1.Tag := (TimerSpam1.Tag+1) mod 3+1;
    inifile.Free;
    end;
    end;
    [/code]
Sign In or Register to comment.