|
Post by bravesado on Jan 2, 2024 12:46:55 GMT
Hello, I have another question. I am new to this, so please bear with me.
I am attempting to perform a random click within a detected image area. Currently, when I click, it consistently targets the center of the image. Here is the code I'm using:
1 | IF | DETECT IMAGE | Image path: C:\x.bmp::At 548 762 855 280::Match full::Move mouse yes | IMAGE FOUND | CONTINUE 2 | RUN ACTION | MOUSE CLICK | Left click at %MOUSE_X% %MOUSE_Y% 1 time with 0 ms delay
I tried this code, unfortuaniliyt it did not work too.
2 | RUN ACTION | MOUSE CLICK | Left click at %MOUSE_X%::+%RANDOM_1-20% %MOUSE_Y% 1 time with 0 ms delay Could someone assist me in modifying this code so that the mouse click occurs at a random location within the identified image area?
Thanks.
|
|
|
Post by zeak on Jan 3, 2024 23:15:26 GMT
Hi Bravesado,
If you are trying to do a single mouse-click, then I would recommend using Entry instead of a condition (RUN ACTION). Because the variables for %MOUSE_X% and %MOUSE_Y%, are dynamic variables based on the mouses current position, I believe they supersede any action to influence. What I have done in the past is break that part of the code into a separate line that creates a static variable.
please see example code.
1 | IF | DETECT IMAGE | Image path: C:\x.bmp::At 548 762 855 280::Match full::Move mouse yes | IMAGE FOUND | CONTINUE 2 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER1%::%MOUSE_X%::+%RANDOM_0-40%::-20 | AND | 2 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER2%::%MOUSE_Y%::+%RANDOM_0-40%::-20 *3 | %INTEGER1% | %INTEGER2% | 0 | Left Click 3 | RUN ACTION | MESSAGE PROMPT | Mouse X = %INTEGER1%'\n'Mouse Y = %INTEGER2%::::0::OK
P.S. you can also minus an amount at the end of a random number to get it to go into the negative and I always find testing my X Y coordinates with MESSAGE PROMPT first to be handy. Just remark out the mouse click line.
Cheers, Zeak
|
|
|
Post by bravesado on Jan 4, 2024 1:09:09 GMT
Hi Bravesado, If you are trying to do a single mouse-click, then I would recommend using Entry instead of a condition (RUN ACTION). Because the variables for %MOUSE_X% and %MOUSE_Y%, are dynamic variables based on the mouses current position, I believe they supersede any action to influence. What I have done in the past is break that part of the code into a separate line that creates a static variable. please see example code. 1 | IF | DETECT IMAGE | Image path: C:\x.bmp::At 548 762 855 280::Match full::Move mouse yes | IMAGE FOUND | CONTINUE 2 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER1%::%MOUSE_X%::+%RANDOM_0-40%::-20 | AND | 2 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER2%::%MOUSE_Y%::+%RANDOM_0-40%::-20 *3 | %INTEGER1% | %INTEGER2% | 0 | Left Click 3 | RUN ACTION | MESSAGE PROMPT | Mouse X = %INTEGER1%'\n'Mouse Y = %INTEGER2%::::0::OK
P.S. you can also minus an amount at the end of a random number to get it to go into the negative and I always find testing my X Y coordinates with MESSAGE PROMPT first to be handy. Just remark out the mouse click line. Cheers, Zeak It works perfekt! Thank you Zeak once again for sharing your expertise and helping me overcome the challenge. Your contribution has been immensely valuable, and I truly appreciate it.
|
|