move mouse further based on random position Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fuykaaaa

move mouse further based on random position

25 Jun 2018, 10:11

Sorry if double post couldn't find first one
This is what I came with so far and it seems to do intended work
Spoiler
So it finds the image moves the cursor and clicks as intended, now the hard part which I want to do comes in play...
Is it possible based on that FoundX FoundY to calculate it and push it further? It's hard to explain.
I made a paint image to make it easier for you to understand it and help me
https://imgur.com/a/OAzAn2e
Basicly the red dots are the images which are found (np with that) now based on the dot position I want to push my mouse cursor further as the green arrows indicate
I can't just add pixels to mousemove because it will not work since the image is randomly placed and based off that I want to move my cursor :(
Hope it's clear enough to understand and someone will be able to help me (I know it's not easy)
Thanks in Advance
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: move mouse further based on random position  Topic is solved

25 Jun 2018, 12:20

its not clear what u want. what is the constraint on where this new MouseMove destination point should appear?
fuykaaaaa
Posts: 5
Joined: 25 Jun 2018, 10:09

Re: move mouse further based on random position

25 Jun 2018, 13:38

swagfag wrote:its not clear what u want. what is the constraint on where this new MouseMove destination point should appear?
Based on image found to push the cursor further to the edge of the screen
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: move mouse further based on random position

25 Jun 2018, 14:04

fuykaaaaa wrote:... push the cursor further to the edge of the screen
so this then:
Spoiler
the cursor is pushed to the edge of the screen, whichever closest that might be
fuykaaaaa
Posts: 5
Joined: 25 Jun 2018, 10:09

Re: move mouse further based on random position

25 Jun 2018, 14:09

yes this is somewhat what im looking for
basicly the image is always the same, the position of the image is random, and based on which part its placed it should push the cursor to the edge like in your picture
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: move mouse further based on random position

25 Jun 2018, 15:54

Code: Select all

#NoEnv
#SingleInstance Force
CoordMode Mouse, Screen

msg = 
(LTrim
	Orig: ({}, {})
	New: ({}, {})
)

SetTimer, Update, 25
Esc::ExitApp

Update:
	MouseGetPos, xOrig, yOrig
	xNew := xOrig, yNew := yOrig
	offsetPoint(xNew, yNew)
	ToolTip % Format(msg, xOrig, yOrig, xNew, yNew), 500, 500
return

offsetPoint(ByRef x, ByRef y) {
	static W := A_ScreenWidth
		, H := A_ScreenHeight
		, xMid := W // 2
		, yMid := H // 2

	if (x < xMid) ; II / III
	{
		if (y < yMid) ; II
			(x < y) ? x := 0 : y := 0
		else ; III
			(x < y - yMid) ? x := 0 : y := H
	}
	else ; I / VI
	{
		if (y < yMid) ; I
			(W - x < y) ? x := W : y := 0
		else ; VI
			(W - x < H - y) ? x := W : y := H
	}
}
based off of:
Spoiler
fuykaaaaa
Posts: 5
Joined: 25 Jun 2018, 10:09

Re: move mouse further based on random position

25 Jun 2018, 15:58

the code looks very complicated to me, I can't test it now, but can you walk me thru it a bit? It will help me to understand it better and how to add it to my existing code I made,
Really thank you man I think this is what I wanted, I want to learn so much :S
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: move mouse further based on random position

25 Jun 2018, 16:11

you needn't concern urself with anything other than the function, the rest is just fluff for demonstration purposes only. incorporated in your code it would look like this:

Code: Select all

MouseGetPos, StartX, StartY 

ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, X.png
offsetPoint(FoundX, FoundY) ; augment the coords now
If ErrorLevel = 0
MouseMove, %FoundX%, %FoundY%
Sleep, 1
MouseClick, left
Sleep, 1 

MouseClick, left 
SendInput, {Q} 
Sleep, 1


Send {Q up}
If Errorlevel = 1
Sleep, 10

MouseMove, StartX, StartY 
Sleep, 15
MouseClick, left
return
as far as the function goes, there isnt much to explain really, its a bunch of if-statements:
  1. determine if point lies to the left or right of the y-axis
  2. then determine if it lies above or below the x-axis. thats your quadrant
  3. depending on the quadrant and the x/y values, change them accordingly.
fuykaaaaa
Posts: 5
Joined: 25 Jun 2018, 10:09

Re: move mouse further based on random position

25 Jun 2018, 16:38

It just pops a msg box telling me the origin? It doesnt do anything else besides that, and my mouse movement seems to stop working
fuykaaaaa
Posts: 5
Joined: 25 Jun 2018, 10:09

Re: move mouse further based on random position

25 Jun 2018, 16:55

I've been messing around with it and I can't get it to work properly, not sure if you understood me correctly either :(
This calc needs to be done "on the fly" and I think cant use screen commands since not using winactive inside the game (game blocks it)
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: move mouse further based on random position

25 Jun 2018, 17:56

  • yes, my script just shows you in a tooltip what the altered coordinates would be. it doesnt do anything else besides that and it was never intended to.
  • if youve tried something and it doesnt work, show what youve tried and explain what doesnt work. otherwise, one could only guess and look where guesswork gets you
  • if youre under the impression that im misunderstanding anything, point it out and elaborate on it. I very well might be. I doubt i am, taking your earlier confirmation into consideration, but I might be.
  • the calculation needs to be performed, at the very latest, right before u make the call to MouseMove. what "on the fly" entails is entirely the script's prerogative
  • CoordMode, ???, Screen is irrelevant. U can use Window too, but you'll have to use you game window's width/height instead
  • .. since not using winactive inside the game - idk what u meant by this.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 161 guests