Jump to content

Running a macro in the background


pPp
 Share

Recommended Posts

I have created a simple macro to use for fun... this macro is used for the SNES game Dual Orb 2 on ZSNES9x Emulator... The macro basically will walk left and right untill it enters a random battle then holds up and presses X to select auto fight in the battle menu.

I was wondering if it is possible to somehow make the macro work in the background, so that I could search the internet or do other things while the macro is running. Currently the macro will continue to run wether or not the Snes window is the active window or not, but it will run on whatever is the active window instead of staying in the window I want (the snes window).

Here is my script incase it will be helpful.

HotkeySet ("{END}", "Stop")
HotkeySet ("{HOME}", "Start")
Func Start ()
While True
Send("{LEFT 5}");Presses the Left key 5 times
Send("{RIGHT 5}");Presses the Right key 5 times
Send("{LEFT 5}");Presses the Left key 5 times
Send("{RIGHT 5}");Presses the Right key 5 times
Send("{UP down}");Holds the Up key down
Send("{x}");Presses the x key 1 time
Send("{UP up}");Releases the Up key
WEnd
EndFunc
While (1)
Sleep (1)
WEnd
Func Stop ()
        Exit 0
EndFunc

I searched on google and looked around the forum but was unable to find an answer, if it has already been answered please point me in the right direction. Thanks in advance for your responces. :)

Link to comment
Share on other sites

Thanks for your replies!

Well I tried using the WinActive command, this does make the macro only work in the Snes window, but it doesn't make the macro to continue running in the snes window when I change windows. (but it is good that it will not mess anything else up, kind of pauses the macro untill i go back to the snes)

I then tried to add the ControlSend instead of the Send command... for some reason when I did this nothing happend what so ever. The macro no longer runs (although the start and stop functions still work, the ControlSend appears to just not work). Perhaps I am confused on how I should be entering the code? Here is the edited code. And yes the WinActive code is still in there, although it should probally be removed in order for the ControlSend to possibly work when the Snes is not the main window, but it wasn't working even when it is the main window.

HotkeySet ("{END}", "Stop")
HotkeySet ("{HOME}", "Start")
Func Start ()
While True
IF WinActive ("ZSNESWIN") Then
ControlSend("ZSNESWIN", "", "", "{LEFT}");Presses the Left key 1 time
ControlSend("ZSNESWIN", "", "", "{RIGHT}");Presses the Right key 1 time
ControlSend("ZSNESWIN", "", "", "{LEFT}");Presses the Left key 1 time
ControlSend("ZSNESWIN", "", "", "{RIGHT}");Presses the Right key 1 time
ControlSend("ZSNESWIN", "", "", "{UP down}");Holds the Up key down
ControlSend("ZSNESWIN", "", "", "{x}");Presses the x key 1 time
ControlSend("ZSNESWIN", "", "", "{UP up}");Releases the Up key
EndIf
WEnd
EndFunc
While (1)
Sleep (1)
WEnd
Func Stop ()
        Exit 0
EndFunc
Link to comment
Share on other sites

I left the controlID blank because I have no idea what it is....

After reading about it here, I found out you can use AutoIt Window Info Tool to find the information on controlID.. the results were:

>>>> Control <<<<

Class:

Instance:

ClassnameNN:

Advanced (Class):

ID:

Text:

Position:

Size:

ControlClick Coords:

Style:

ExStyle:

Handle: 0x00020116

I'm assuming since everything was blank, that this means it will not be possible to use the control send function... or is there another way to find this information?
Link to comment
Share on other sites

ControlSend("ZSNESWIN", "", "", "{LEFT}");Presses the Left key 1 time

This may be correct syntax.

If you left ControlID empty then AutoIt sends it to control which has focus. This is "undocumented" feature.

If it doesn't work then your target application may have built-in some antibot functions or it has non standard controls.

Link to comment
Share on other sites

Well I can't get the controlsend to work for some reason... well I don't think I'll be able to get it to work unless it is the window that is in focus. If anyone has any other ideas feel free to respond though.

This is my code now...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Script Version: 2.0
 Author:         Justin

 Script Function:
    Dual Orb 2 (SNES) Auto Fighter. Enters random battles and executes the auto fight
    command. Periodically uses mana potions to restore MP.

#ce ----------------------------------------------------------------------------

; Script Start
Global  $Count = 1
HotkeySet ("{END}", "Stop")
HotkeySet ("{HOME}", "Start")
Func Start ()

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;The Basic Random Encounter/Auto Fight Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While True
IF $Count < 450 Then
Send("{LEFT 5}");Presses the Left key 5 times
Send("{RIGHT 5}");Presses the Right key 5 times
Send("{LEFT 5}");Presses the Left key 5 times
Send("{RIGHT 5}");Presses the Right key 5 times
Send("{UP down}");Holds the Up key down
Send("{x}");Presses the x key 1 time
Send("{UP up}");Releases the Up key
$Count += 1

;;;;;;;;;;;;;;;;;;;;;;
;The Mana Potion Code;
;;;;;;;;;;;;;;;;;;;;;;
Else
Sleep (20000);20 second delay   
Send("{UP down}");Holds the Up key down
Send("{x}");Presses the x key 1 time
Send("{UP up}");Releases the Up key 
Sleep (20000);20 second delay   
Send("{UP down}");Holds the Up key down
Send("{x}");Presses the x key 1 time
Send("{UP up}");Releases the Up key 
Sleep (60000);60 second delay
Send("{x}");Makes sure the battle is over
Sleep (5000);5 second delay
Send("{x}");Makes sure the battle is over
Sleep (5000);5 second delay
Send("{x}");Makes sure the battle is over
Sleep(5000);5 second delay
Send("{z}");Opens the menu
Sleep (10000);10 second delay
Send("{DOWN}");Moves the cursor to Items on the menu
Sleep (10000);10 second delay
Send("{x}");Selects Items
Sleep (10000);10 second delay
Send("{x}");Selects Use Items
Sleep (10000);10 second delay
Send("{DOWN}");Moves the cursor to Mana Potion
Sleep (10000);10 second delay
Send("{x}");Selects the Mana Potion
Sleep (10000);10 second delay
Send("{Down}");Moves the cursor to 2nd party member
Sleep (10000);10 second delay
Send("{x}");Uses Mana Potion on 2nd party member
Sleep (10000);10 second delay
Send("{z}");Closing Menu
Sleep (5000);5 second delay
Send("{z}");Closing Menu
Sleep (5000);5 second delay
Send("{z}");Closing Menu
Sleep (5000);5 second delay
Send("{z}");Closing Menu
$Count = 1
EndIF
Wend
EndFunc

While (1)
Sleep (1)
WEnd

Func Stop ()
        Exit 0
EndFunc
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...