controlclick,controlsend,postmessage etc..

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Parama
Posts: 40
Joined: 27 Sep 2017, 22:38

controlclick,controlsend,postmessage etc..

01 Nov 2017, 07:52

i wanna run a script that after imagesearching specific image, click coordinate of that image and send a several keys
click is done as a controlclick command and several keys are done as a controlsend or postmessage command because two windows to be run is the same program. and activated window is Program Manager(Title name of wallpaper(?) of computer)
In this situation, Neither of them works or only one of them works.

this is simplified script that i made ( title name of winodow is 1, and 2. coordinate of 1 is (0,0) and 2 is (1025,0) )
What do i do to drive well?

Code: Select all

setbatchlines, -1


f1::
coordmode, mouse,screen
coordmode,pixel,screen

settimer, a, 1000
settimer, b, 1000



a:

imagesearch,vx,vy,0,0,1030,697, C:\Users\me\Desktop\image.bmp

	postmessage,0x100,96,5373953,,1
	sleep,50
	controlclick, X%vx% Y%vy%, 1,,L,1
	sleep,50
	postmessage,0x100,13,1835009,,1
	sleep,50
	postmessage,0x100,102,5046273,,1
	sleep,50
	postmessage,0x100,13,1835009,,1
	sleep,300


return

b:

imagesearch,vvx,vvy,1025,0,1900,697, C:\Users\경택\Desktop\ㅉ.bmp

xx := vvx - 1025
yy := vvy - 0


	postmessage,0x100,96,5373953,,2
	sleep,50
	controlclick, X%xx% Y%yy%, 2,,L,1
	sleep,50
	postmessage,0x100,13,1835009,,2
	sleep,50
	postmessage,0x100,102,5046273,,2
	sleep,50
	postmessage,0x100,13,1835009,,2
	sleep,300


return




f2::



settimer, a, off
settimer, b, off


return


User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: controlclick,controlsend,postmessage etc..

01 Nov 2017, 16:45

Do you have a document for referring to what the PostMessage value are, and what they're trying to do? I'm a little lazy to look it up myself :P

What do you mean by Neither works or Only one works? Does that mean both a and b labels are working entirely as you please, but just not together when you expect them to?

I want you to note that your ImageSearch may result in no vlaues for vx, vy, vvx, and vvy. If the image is not found, then it those variables get no value, which your other commands may treat as a 0.

I would consider adding in an If !ErrorLevel or If ErrorLevel=0 immediately after your ImageSearch command. Then wrap the rest of your commmands (That are indented; all the postmessage and controlclicks) inside a Block. The ! would be the logical-not operator.

Code: Select all

a:
imagesearch,vx,vy,0,0,1030,697, C:\Users\me\Desktop\image.bmp
If !ErrorLevel ; indicates that the image was FOUND
{
	postmessage,0x100,96,5373953,,1
	sleep,50
	controlclick, X%vx% Y%vy%, 1,,L,1
	sleep,50
	postmessage,0x100,13,1835009,,1
	sleep,50
	postmessage,0x100,102,5046273,,1
	sleep,50
	postmessage,0x100,13,1835009,,1
	sleep,300
}
return
Without that ErrorLevel check, it is possible you'd get unexpected results; if the image you're looking for ever moves (but you say it's the wallpaper, so it probably doesn't?) but AHK doesn't find the image for some reason, that can result in your code clicking on where the image used to be, not where it is.
Parama
Posts: 40
Joined: 27 Sep 2017, 22:38

Re: controlclick,controlsend,postmessage etc..

01 Nov 2017, 19:54

No This problem is not a very basic issue. Of course, the image search is good. this is interference problem among subroutines
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: controlclick,controlsend,postmessage etc..

01 Nov 2017, 23:17

WM_KEYDOWN := 0x100

List of Windows Messages - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=39218
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], macromint, peter_ahk and 357 guests