image move (right-left) + keyboard follow it Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
rickyang11
Posts: 10
Joined: 24 Jan 2021, 17:50

image move (right-left) + keyboard follow it

Post by rickyang11 » 24 Jan 2021, 18:18

So guys, i'm sorry for my english, i will try to explain my problem slowly.
When the image moves to the left, the keyboard keys will also press left and otherwise. it's like keyboard keys will follow where is the image moves.
Can someone explain me how to make script for it ?
thanks
User avatar
mikeyww
Posts: 5351
Joined: 09 Sep 2014, 18:38

Re: image move (right-left) + keyboard follow it

Post by mikeyww » 24 Jan 2021, 18:21

ImageSearch. Wait. ImageSearch again. If the x value decreases, Send {Left}; if it increases, Send {Right}.
rickyang11
Posts: 10
Joined: 24 Jan 2021, 17:50

Re: image move (right-left) + keyboard follow it

Post by rickyang11 » 24 Jan 2021, 19:51

so, how to change keyboard keys that i want use to move ?
User avatar
mikeyww
Posts: 5351
Joined: 09 Sep 2014, 18:38

Re: image move (right-left) + keyboard follow it

Post by mikeyww » 24 Jan 2021, 21:17

Send {Left} will send the left arrow key.
rickyang11
Posts: 10
Joined: 24 Jan 2021, 17:50

Re: image move (right-left) + keyboard follow it

Post by rickyang11 » 24 Jan 2021, 22:19

ImageSearch. Wait. ImageSearch again. If the x value decreases, Send {Left}; if it increases, Send {Right}.

where to put image file ?
User avatar
mikeyww
Posts: 5351
Joined: 09 Sep 2014, 18:38

Re: image move (right-left) + keyboard follow it

Post by mikeyww » 24 Jan 2021, 22:44

You can put the file anywhere. See Example #1 on the hyperlinked page posted above.
rickyang11
Posts: 10
Joined: 24 Jan 2021, 17:50

Re: image move (right-left) + keyboard follow it

Post by rickyang11 » 26 Jan 2021, 04:51

mikeyww wrote:
24 Jan 2021, 22:44
You can put the file anywhere. See Example #1 on the hyperlinked page posted above.
i try to make the script this is it. Any problem with it ?
Cuplikan layar 2021-01-26 164800.png
Cuplikan layar 2021-01-26 164800.png (6.99 KiB) Viewed 405 times
User avatar
mikeyww
Posts: 5351
Joined: 09 Sep 2014, 18:38

Re: image move (right-left) + keyboard follow it

Post by mikeyww » 26 Jan 2021, 06:58

Read documentation for ImageSearch. *n uses a numeric argument for variation. If you do not need it, remove it.

Coordinates will be relative to the active window unless you use CoordMode. If you intend to search the entire screen, you would want to add that command. Click and ImageSearch use different CoordMode target types.

The second line in the block does not use AHK commands.
rickyang11
Posts: 10
Joined: 24 Jan 2021, 17:50

Re: image move (right-left) + keyboard follow it

Post by rickyang11 » 26 Jan 2021, 08:36

ok thanks, i will try to correction my script, and Hisoka who pm me, im sorry cant reply because i still can't use pm feature.
User avatar
HiSoKa
Posts: 108
Joined: 27 Jan 2020, 15:43

Re: image move (right-left) + keyboard follow it

Post by HiSoKa » 26 Jan 2021, 08:41

when that image moving to left there are any distinct sign for that ?

i mean did image change when moving left or right , or that image it isn't change just moving in some direction ..
User avatar
mikeyww
Posts: 5351
Joined: 09 Sep 2014, 18:38

Re: image move (right-left) + keyboard follow it

Post by mikeyww » 26 Jan 2021, 09:48

Upon sequential searches for the image, if x decreases, it means that the new image is left of the previous image.
rickyang11
Posts: 10
Joined: 24 Jan 2021, 17:50

Re: image move (right-left) + keyboard follow it

Post by rickyang11 » 26 Jan 2021, 10:20

HiSoKa wrote:
26 Jan 2021, 08:41
when that image moving to left there are any distinct sign for that ?

i mean did image change when moving left or right , or that image it isn't change just moving in some direction ..
the image is just moving in two direction, left and right, it is didnt change anything and same.
So i make this script for game.
And if i do manually, i need to press keyboard to follow that image.
IMG_20210126_221425.jpg
IMG_20210126_221425.jpg (14.85 KiB) Viewed 347 times
Green fish is image moving and i need to press keyboard to move green shape, following green fish image.
Attachments
IMG_20210126_221425.jpg
IMG_20210126_221425.jpg (14.85 KiB) Viewed 347 times
User avatar
HiSoKa
Posts: 108
Joined: 27 Jan 2020, 15:43

Re: image move (right-left) + keyboard follow it  Topic is solved

Post by HiSoKa » 26 Jan 2021, 11:04

@mikeyww yes , but i think he didn't understand you , because he did quotes your first reply Literally then he writed it in second line code.

@rickyang11 this it general idea for what you want to do , just need to some adjust from expert like mikey :mrgreen: if u need:

Code: Select all

CoordMode Pixel
var:=0
f1::
Loop
 {
 ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, d:\strike.png
 
  if (ErrorLevel = 2)
   MsgBox Could not conduct the search.
  
  else if (ErrorLevel = 1)
   MsgBox Icon could not be found on the screen.
  
  else
   loop
  {
  if (FoundX > var)          ;moved right
   {
    MsgBox, Image moving right         ;replace With Send, {Right} if u need
    var:=FoundX
   }

  if (FoundX < var)          ;moved left
   {
    MsgBox, Image moving left         ;replace With Send, {Left} if u need
    var:=FoundX
   }
   break
  }
  return
  
 }
 return
 
esc::ExitApp
rickyang11
Posts: 10
Joined: 24 Jan 2021, 17:50

Re: image move (right-left) + keyboard follow it

Post by rickyang11 » 26 Jan 2021, 19:49

HiSoKa wrote:
26 Jan 2021, 11:04
@mikeyww yes , but i think he didn't understand you , because he did quotes your first reply Literally then he writed it in second line code.

@rickyang11 this it general idea for what you want to do , just need to some adjust from expert like mikey :mrgreen: if u need:

Code: Select all

CoordMode Pixel
var:=0
f1::
Loop
 {
 ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, d:\strike.png
 
  if (ErrorLevel = 2)
   MsgBox Could not conduct the search.
  
  else if (ErrorLevel = 1)
   MsgBox Icon could not be found on the screen.
  
  else
   loop
  {
  if (FoundX > var)          ;moved right
   {
    MsgBox, Image moving right         ;replace With Send, {Right} if u need
    var:=FoundX
   }

  if (FoundX < var)          ;moved left
   {
    MsgBox, Image moving left         ;replace With Send, {Left} if u need
    var:=FoundX
   }
   break
  }
  return
  
 }
 return
 
esc::ExitApp
Thank you very much for yout help. I will test to my game.
rickyang11
Posts: 10
Joined: 24 Jan 2021, 17:50

Re: image move (right-left) + keyboard follow it

Post by rickyang11 » 27 Jan 2021, 22:43

mikeyww wrote:
26 Jan 2021, 09:48
Upon sequential searches for the image, if x decreases, it means that the new image is left of the previous image.
i have question, i want to edit the image with photoshop, can ahk recognize it ?
and
i have problem, when i try to use imagesearch for images that vibrate quickly, ahk can't found it, is there a way to solve it?
Post Reply

Return to “Ask For Help”