Jump to content

Using IE.au3 with HotKeySet


Recommended Posts

Hello everyone,

I want the programm to click two buttons (item_66029 and btn-add-to-cart) when I press the down key. It seems I do something wrong. Any ideas?

Thanks for the help!

#include <IE.au3>

HotKeySet ( "{DOWN}","_start" )
HotKeySet ( "{UP}","_pause" )
HotKeySet ( "{END}","_exit" )

Global $go = 0


While(1)
    If($go) Then
       Local $button1 = _IEGetObjByName ($oIE,"item_66029")
       Local $button2 = _IEGetObjById ($oIE, "btn-add-to-cart")
       _IEAction ($button1,"click")
       Sleep(1)
       _IEAction ($button2,"click")
        $go=0
    Else
        Sleep(1)
    EndIf
WEnd

Func _start()
    $go = 1
EndFunc
Func _pause()
    $go = 0
EndFunc
Func _exit()
    Exit
EndFunc

 

Link to comment
Share on other sites

Thanks. I put the following definition in:

 

Global $oIE = _IECreate ("https://xxx")

But when I do this the website opens (even if the website is already open). I dont want that the programm to restart the explorer and the website. I just want the programm to click two buttons (item_66029 and btn-add-to-cart) when I press the down key (while I am on the website).

Link to comment
Share on other sites

@Nine @JLogan3o13 It is nearly similiar but instead of mouse clicks I want to use a more "intelligent" version (by using things like IEGetObjByName). But right now the programm restarts the explorer and the website. I want the programm to only click the two buttons while I am on the website. Any ideas?

Link to comment
Share on other sites

The problem with this thread (and like the other "similar" one) is that you ask us to tell you how to solve your issue but you do not provide the essential information of why is this an issue and what do you want to achieve at the end.  I suggest you first start telling us the web site that you want to automate (or at least a screenshot of the pages), the end goal of the script, and a clear description of the issue.  Unless you can adduce a more detailed documentation of your problem, I am afraid it is going to be hard to help you.

Link to comment
Share on other sites

3 hours ago, Nine said:

The problem with this thread (and like the other "similar" one) is that you ask us to tell you how to solve your issue but you do not provide the essential information of why is this an issue and what do you want to achieve at the end.  I suggest you first start telling us the web site that you want to automate (or at least a screenshot of the pages), the end goal of the script, and a clear description of the issue.  Unless you can adduce a more detailed documentation of your problem, I am afraid it is going to be hard to help you.

Ok, I try to explain what I want to achieve:

1) I want to make a reservation on this website (https://pretix.eu/dnb/reservierung-f/). Everyday 9 AM tickets will be released. At this time the website looks like in the attached picture. To make the reservation I have to click on one of the boxes and then click on the "anmelden"-button. And I have to do it really fast because the tickets are gone in 1-2 seconds. => I want a program that automatically opens the website and does this steps at 9 AM. So far I have this (imo only the feature that the program starts itself at 9 AM is missing)

#include <IE.au3>

Call ("SignIn")

Func SignIn ()
Global $oIE = _IECreate ("https://pretix.eu/dnb/reservierung-f")

Local $button1 = _IEGetObjByName ($oIE,"item_66932")
Local $button2 = _IEGetObjById ($oIE, "btn-add-to-cart")

_IEAction ($button1,"click")
Sleep(100)
_IEAction ($button2,"click")
EndFunc

2) If I didnt manage to get a ticket sometimes someone cancels its ticket. To make sure that I get this ticket (and not someone else) I have to click the refresh button constantly until a "free" box is shown again. Then I have to click on the box and  the "anmelden"-button.

So far I made a program that presses the refresh button every 4 seconds (just a bunch of mouse click commands) and I tried to make a program that quickly clicks on the box and the "anmelden"-button (the topic is about this program). The current problem I have is that I cannot switch very fast from the reload program to the second program and that the second problem is a little bit slower when it always has to restart the explorer.

Why is the program in 1) and the program I posted at the beginning of the thread different? Because right now I manually refresh and then activate program with the down key (which does not work):

#include <IE.au3>

HotKeySet ( "{DOWN}","_start" )
HotKeySet ( "{UP}","_pause" )
HotKeySet ( "{END}","_exit" )

Global $go = 0
Global $oIE = _IECreate ("https://pretix.eu/dnb/reservierung-f")

While(1)
    If($go) Then
       Local $button1 = _IEGetObjByName ($oIE,"item_66932")
       Local $button2 = _IEGetObjById ($oIE, "btn-add-to-cart")
       _IEAction ($button1,"click")
       Sleep(1)
       _IEAction ($button2,"click")
        $go=0
    Else
        Sleep(1)
    EndIf
WEnd

Func _start()
    $go = 1
EndFunc
Func _pause()
    $go = 0
EndFunc
Func _exit()
    Exit
EndFunc

I appreciate any help!

 

 

Website2.JPG

Edited by Franz135
Link to comment
Share on other sites

Thank you for taking the time to describe your issue.  Here one way you could do it :

#include <Constants.au3>
#include <IE.au3>

; should be started at 8h50 every day
If Not @Compiled Then Exit MsgBox ($MB_SYSTEMMODAL,"Error", "You must compile this script and add it to task scheduler")
MsgBox ($MB_SYSTEMMODAL,"", "Reservation manager started", 5)
Local $oIE = _IECreate ("https://pretix.eu/dnb/reservierung-f")

While Int(@HOUR) < 9
  Sleep (100)
WEnd

If SignIn($oIE, 20, 0) Then ; perform initial reservation with no sleep
  MsgBox ($MB_SYSTEMMODAL,"","Successful reservation")
ElseIf SignIn ($oIE, 500, 1000) Then ; reservation attempt with 1 sec sleep at each iteration
  MsgBox ($MB_SYSTEMMODAL,"","Reservation found because of cancellation")
Else
  MsgBox ($MB_SYSTEMMODAL,"","Unable to make reservation")
EndIf

_IEQuit ($oIE)

Func SignIn (ByRef $oIE, $iAttempt, $iPause)
  Local $button1, $button2
  For $i = 1 to $iAttempt
    Sleep ($iPause)
    _IEAction ($oIE, "refresh")
    _IELoadWait ($oIE)
    $button1 = _IEGetObjByName ($oIE,"item_66932")
    If Not IsObj ($button1) Then ContinueLoop
    $button2 = _IEGetObjById ($oIE, "btn-add-to-cart")
    If IsObj ($button2) Then
      _IEAction ($button1,"click")
      Sleep(100)
      _IEAction ($button2,"click")
      Return True
    EndIf
  Next
  Return False
EndFunc

I would personally put this compiled script into task scheduler to start every day just before 9h00AM. 

Edit : I just saw that there is a different button to push for cancellation part, you will need to adjust the script accordingly.

Edited by Nine
Link to comment
Share on other sites

1) Like this :

While Number(@HOUR & "." & @MIN) < 8.45

2) The parameters that are passed to the function SignIn tell the function how many times it has to loop before returning False.  If it finds a match with the button objects, it will return True.  So you must adjust the $iAttempt accordingly, to cover the duration that you want (increase the $iAttempt for a longer duration).

Link to comment
Share on other sites

49 minutes ago, Nine said:

2) The parameters that are passed to the function SignIn tell the function how many times it has to loop before returning False.  If it finds a match with the button objects, it will return True.  So you must adjust the $iAttempt accordingly, to cover the duration that you want (increase the $iAttempt for a longer duration).

Which value did you set? I am not sure which number represents the number of attempts. 500, correct?

Edit: And where did you set the 1 sec sleep at each iteration? How would I set 2 sec sleep for example?

Edited by Franz135
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...