Jump to content
Sign in to follow this  
Skizzy

If Then loop with Memory Reading

Recommended Posts

Skizzy

Is there a more... optimized way to write this script? It's very unreliable and will often action() over #2 when it should have action()'d on #1. I feel like it's something to do with the sleep(xxx), but I've tried so many different ways and seems I can't get it down. The memory address is accurate and is static.

#include <NomadMemory.au3>
   #include <GUIConstants.au3>
   #include <Misc.au3>
   #include <Array.au3>


   $ID=_MemoryOpen(ProcessExists("application.exe"))
   $Address=0x19790F64
   $value=_MemoryRead($Address,$ID ,"char[5]")

Global $Paused


HotKeySet("{HOME}", "TogglePause")
HotKeySet("{END}", "Terminate")

$Count = 10000 ;

While 1
   MouseMove ( 643, 760, 0 ) ;
   MouseClick("left")
   Sleep(50)
   Send( "{BACKSPACE 5}" )
   Sleep(50)
   Send ($Count)
   Sleep(50)
   MouseMove ( 531, 841, 0 ) ;
   Mouseclick("left")
   $Count = $Count + 1
   Sleep(50)
   MouseMove ( 958, 461, 0 ) ;
   MouseClick("left")
   Sleep(200)
   MouseMove ( 724, 322, 0 ) ; #1
If $value > 700 Then
   action()
EndIf
   Sleep(100)
   MouseMove ( 724, 370, 0 ) ; #2
   Sleep(400)
If $value > 700 Then
   action()
EndIf
WEnd


Func action()
Sleep(50)
MouseClick("left")
Sleep(200)
MouseMove ( 1442, 879, 0 )
MouseClick("left")
Sleep(200)
MouseMove ( 849, 722, 0 )
Mouseclick("left")
EndFunc

Any help would be very appreciated! I have spent hours on writing this thing from scratch, and being so close to being complete and it not cooperating like it should is quite frustrating. ;)

Edited by Skizzy

Share this post


Link to post
Share on other sites
water

What kind of application do you try to automate? Wouldn't it be easier and more reliable to use Send or Control commands?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Inverted

There are things missing. What is that $value variable ?

Otherwise this is just mouse moving, cliking and clicking, we can't help you.

Share this post


Link to post
Share on other sites
Skizzy

What kind of application do you try to automate? Wouldn't it be easier and more reliable to use Send or Control commands?

It's just something to make my life a bit easier. I do use a few Send commands in there, and I guess I could use Control. Might clear up a few lines, but it's not top priority at this moment. Just trying to make the If $value Then action() commands a bit more reliable. ;)

There are things missing. What is that $value variable ?

Otherwise this is just mouse moving, cliking and clicking, we can't help you.

$value is:
$value=_MemoryRead($Address,$ID ,"char[5]")

You probably just missed it because of how sloppy my coding is, sorry! :)

Edited by Skizzy

Share this post


Link to post
Share on other sites
Skizzy

I'm wondering if it has something to do with the value being a decimal for the memory address. For example, the address has a value of 767.2. A char[6] make sense here, correct? I can see the value changing while the macro does its thing and the address stays constant, but sometimes action() does not happen despite the address showing 767.2.

Edit: If the script fails to perform action() when $value is > 700, and I terminate the script and run it again, it acknowledges it instantly, and does action() like it should. Ugh, I don't understand.

Edited by Skizzy

Share this post


Link to post
Share on other sites
water

Once again: Memory reading isn't needed 99.9% of the time. Almost every application can be automated using Send and Control commands. To make your script run reliable independant of screen size etc. I would strongly recommend to search for another approach and drop memory reading and mouse moving.

Tell us what application you try to automate, what data you need to read and what buttons etc. you need to click on.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Skizzy

Ah, it's so satisfying when you troubleshoot an issue yourself. Finally got it done after several hours working on this thing today!

Basically I just simplified my While statement, put the Memory information in there, and added a Refresh() function which just contains everything I used to have in the While section.

While 1
$ID=_MemoryOpen(ProcessExists("application.exe"))
$Address=0x19790F64
$dps=_MemoryRead($Address, $ID, "char[6]")
   If $value > 700 Then
   Action()
   Else
   Refresh()
   EndIf
WEnd
Edited by Skizzy

Share this post


Link to post
Share on other sites
Bert

Once again: Memory reading isn't needed 99.9% of the time. Almost every application can be automated using Send and Control commands. To make your script run reliable independant of screen size etc. I would strongly recommend to search for another approach and drop memory reading and mouse moving.

Tell us what application you try to automate, what data you need to read and what buttons etc. you need to click on.

The OP is ignoring your question for if he is honest you know what will happen. ............"Click"

Share this post


Link to post
Share on other sites
water

I know ... that's why I ask ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
czardas

When I see all those clicks and mouse moves my PC just growls 'Don't you dare allow that code anywhere near my processor!'. ;)

Edited by czardas

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  

×