Jump to content


Photo

GG's Find Clickable Locs Window Aid


  • Please log in to reply
34 replies to this topic

#1 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 21 March 2011 - 11:05 PM

This code uses the mouse middle button for grabbing window locations. If your mouse doesn't have a middle button, you can change it to read the left button the right button or even a completely different key. This script uses functions from AutoHotkey classic and has no hotkeys to interfere with other running scripts. Make sure you pay attention to the onscreen tooltips. They will help walk you through the process of using this script
When you are done you can rename the created ini file to fit with your own application scripts.
;================================================
; GG's Find Clickables Window Controller Aid

; This is a simple window location/color grabber
; for windows that need to be controlled and/or
; monitored or clicked during a run of that
; particular window or game.

; It will save the data using user-defined keys
; into an ini file that can be read by a script to
; help control the window

; This is a generic version of one I already use in
; several online games so I know it works.

; To keep this simple there is very little errorchecking
; in this script.
 
; Ini data gathered by this program has been used for 
;	in-game crafting
;   reactive fight monitoring
;   harvesting materials
;   healing party members
;	auto use of potions for mana, etc
;	auto looting

; and on a more practical note
;	button clicking for login scripts
;	auto insertion of passwords and login names 
;	auto activating program shortcuts on the desktop

; No hotkeys were injured during the making of this
; script
;------------------------------------------------

#SingleInstance, Force
SetTitleMatchMode, 2
CoordMode, Pixel, relative
CoordMode, Tooltip, relative
Coordmode, Mouse, Relative

keybutton = MButton				; change this if your mouse does't have a middle button
w = w150						; this is the width of the button controls
PgmTitle = GG's Clickable Loc Finder
IniName = Clickable Locs.ini	;the name of the ini file that will be written
LocX = 0						;default values for x and y
LocY = 0

;------------------------------------------------

ShowConfigGui:
Gui, +Resize
Gui, color, 0x8080F0
gui, Add, button,+E0x101 %w% gButtonGetWindowName,		Get Window Name
gui, Add, button,+E0x101 %w% gButtonGetClickableLoc,	Get Clickable Location
gui, Add, button,+E0x101 %w% gButtonGetClickableColor,	Get Clickable Color
gui, Add, button,+E0x101 x10 y110 w70 gButtonShowIni,			Show Ini
gui, Add, button,+E0x101 x90 y110 w70 gButtonClearIni,			Clear Ini
;gui, Add, button,+E0x101 %w% gButtonSaveClickableDat,	Save Clickable Data
Gui, Show,Title, %PgmName%
Winset, AlwaysOnTop, On,  %PgmName%

Return

;------------------------------------------------

GuiClose:
exitapp

;------------------------------------------------

ButtonGetWindowName:
Tooltip, 1. Activate the desired window.`n2. Press the %keybutton% mouse button anywhere inside the window's border to grab the clickable color for %LocX% %LocY%.
SoundBeep, 400, 500
KeyWait, %keybutton%, D 
ToolTip 
KeyWait, %keybutton%, U
WinGetTitle, WinName, A
Gosub, GetKeyName
IniWrite, %WinName%, %IniName%, Init, %KeyName%Win
SoundBeep, 1000, 500
Run,Notepad %IniName%
Return

;------------------------------------------------

ButtonGetClickableLoc:
Tooltip, 1. Activate the desired window.`n2. Place the mouse cursor on the window object to be located.`n3. Press the %keybutton% mouse button.
SoundBeep, 400, 500
KeyWait, %keybutton%, D 
ToolTip 
KeyWait, %keybutton%, U
MouseGetPos, LocX, LocY
Gosub, GetKeyName
IniWrite, %LocX%, %IniName%, Init, %KeyName%X
IniWrite, %LocY%, %IniName%, Init, %KeyName%Y
SoundBeep, 1000, 500
Run,Notepad %IniName%
Return

;------------------------------------------------

ButtonGetClickableColor:
If ((%LocX% = 0) || (%LocY% = 0))
{	MsgBox,,, Please set a clickable location first, Thank you.
	Return
}
Tooltip, 1. Activate the desired window.`n2. Press the %keybutton% mouse button anywhere inside the window's border to grab the clickable color for %LocX% %LocY%.
SoundBeep, 400, 500
KeyWait, %keybutton%, D 
ToolTip 
KeyWait, %keybutton%, U
PixelGetColor, LocColor, %LocX%, %LocY%, RGB
;Gosub, GetKeyName
IniWrite, %LocColor%, %IniName%, Init, %KeyName%Color
SoundBeep, 1000, 500
Run,Notepad %IniName%
Return

;------------------------------------------------

GetKeyName:
Inputbox, KeyName, What name do you want to use for this key in the ini file?`nNote: The letters X and Y will be appended to the location coordinates. the word Color will be appended to any saved colors.
Return

;------------------------------------------------

ButtonShowIni:
Run,Notepad %IniName%
Return

;------------------------------------------------

ButtonClearIni:
MsgBox,1,Delete Ini, Are you sure you want to delete %IniName%
IfMsgBox, OK
FileDelete, %IniName%
Return

;================================================


#2 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 22 March 2011 - 07:31 AM

For you purists out there. There is one major reason why I separated out the function for grabbing a control's location from it's color. In many games and windows, hovering the mouse over a control changes it's color significantly through either highlighting or some other means of identifying the control the mouse is on.

By separating out the location from the color acquisition, the mouse does not have to be over the control to grab it's color -- just somewhere within the active window. This means you get the true un-highlighted color of the control at that window xy location.

Just a heads up. Also you aren't limited to grabbing just one window or control with this program. Just provide the key names for each control you wish to grab and they will be saved to the ini file. One more thing, if you repeat a key name, that key will be overwritten in the ini file so if you mess up with a grab you can go back and redo the same key again.

#3 tidbit

tidbit
  • Moderators
  • 2324 posts

Posted 22 March 2011 - 03:11 PM

i could see how ths could be useful, especially for beginners.

you should include a demo/sample on how to retrieve the data. Iniread/write and clicking the coords and pixel color. like a "replay" button.

#4 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 23 March 2011 - 12:46 AM

thanks tidbit. let me think on this and see if i can come up with a practical and relevant example to use the data on. One simple one i can think of at the moment is in Lord of the Rings Online where you have to dismount before you can fight or harvest. To do that you have to click the mount's dismount button first, then begin your harvest or fight sequence. That button only shows up when mounted so it's a fair example of a non-persistant button that really isn't a window-spy identifiable control. maybe i can put something together on that or perhaps a yahoo mail login with fake password and username and click the login button. That way i could show getting the field locations and button location and color and even how to full-screen the yahoo window. hmmm. so many programs. so little time :) maybe i should do a wegame video of the process in action...

#5 LostInCode

LostInCode
  • Guests

Posted 25 March 2011 - 08:43 PM

I've been coding autohotkey off an on for 10 years but I still don't get it entirely. The concept of using if else, loop is very confusing. Can you suggest of a good way to learn how to code? I know i'm missing something that make me go "ah-ha!!".

#6 LostInCode

LostInCode
  • Guests

Posted 25 March 2011 - 08:50 PM

Can I suggest creating a youtube tutorial of autohotkey and link it?

#7 niraxar

niraxar
  • Members
  • 17 posts

Posted 01 April 2011 - 09:08 AM

i am also trying to learn AHK. coming from a linux background, i find its syntax pretty weird. it is just ridiculous that %var% and var mean the same thing. not to speak of "Sleep 100" and "Sleep, 100" being same ... i wonder where such design specs came from.

i dont know about you, but i feel like smashing the computer while trying to learn AHK.

#8 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 01 April 2011 - 06:48 PM

Apples and oranges. Ahk is very forgiving of some syntactical transgressions that would break a linux script. Just as GNU means Gnu is Not Unix. AHK is not Linux. My recommendation: Forget what you "think" you know and get in there and enjoy. Programs can be built the same way in essentially ALL computer languages. 1) concept, 2) outline, 3) stepwise refinement, 4) release 5) maintain.

Yes, Learning any new language can be massively frustrating. But carrying preconceptions from one platform/language to the next can be devastating to any form of learning. Let go of your preconceptions, feel the flow of the language. Take it back to basics. Use standard constructs and let the language teach you instead of you trying to make it fit a different form. Coding and programming are not the same things. Coding is Yoga. Programming is Zen.

#9 kyj00

kyj00
  • Members
  • 10 posts

Posted 03 April 2011 - 05:48 AM

Thanks for your input. Can you share a script where I can go to a website and be able to auto populate the user id and the password?

#10 niraxar

niraxar
  • Members
  • 17 posts

Posted 03 April 2011 - 01:21 PM

Coding is Yoga. Programming is Zen.


Touche !

that was my first day with AHK. Now I am a little more fluent in it ... and I am a fast learner. I am impressed with AHK's capabilities ... I have been able to do things with AHK that had foxed me for quite a long time ...

I use cygwin (basically shell scripts) very extensively for automated file management .. but so far there was no way to call a shell script from the windows world (for example from the task scheduler) , even though calling native windows programs is a cinch from the cygwin shell .. essentially it was a one way street so far.

not anymore ... i can use AHK to send commands to cygwin shell ... moreover i can schedule the tasks for automation, which is precisely why i use cygwin ...

#11 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 03 April 2011 - 06:16 PM

To kyj00: sure i can do that, give me a bit and 'll strip down my own login. manager and put an abbreviated version up on the scripts section. One thing tho, it uses an ini file so I'll have to post a snippet of what that looks like along with the script.

To Niraxar: It only gets better.

#12 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 03 April 2011 - 07:39 PM

To kyj00

About that login manager. Check out
http://www.autohotke...p=433638#433638

it's a little intimidating at first but actually pretty simple once you see the reasoning behind it.

#13 bruno

bruno
  • Members
  • 161 posts

Posted 04 April 2011 - 10:39 PM

Can I suggest creating a youtube tutorial of autohotkey and link it?

i suggest a twitter service :lol:

#14 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 05 April 2011 - 05:10 AM

I'm still considering my options here. Writing a tutorial for AutoHotkey is not going to be simple or a small piece of work. There will need to be more items addressed than one simple application given the immense flexibility and sheer number of commands AutoHotkey provides. Personally I'm leaning more to a written tutorial with video enhancements that can be built in stages rather than a purely video presentation. The reason for that is that AutoHotkey is a computer language and as such would be difficult if not impossible to convey without some serious interaction from the target audience. Just to mention a few sticking points...
Computer programming is more than just coding with a language. Programming is a thought process coupled with a methodology and teaching people to alter the way they normally think is not an easy or direct path. One must learn to think backwards from the goal to create a workable solution to a programming problem. The best programmers seem to do this unconsciously. The rest of us have to work at it.

Then you have to put in place a generic programming structure that people can build on to "grow" an application from concept to completion. Something that can work for any computer program you may be able to imagine. This generally requires an introduction to some non-language specific pseudocode framework that you can use to support common programming constructs like looping, variables, comparison operations, conditionals, data structures, file handling, indirect addressing, and program flow control. In effect you have to build a common language between teacher and student to be able to rationally discuss programming constructs.

Then you have to teach people a debugging methodology because as a program grows from concept toward a final solution errors will be introduced into the code which will have to be dealt with before additional progress can be realized.

Once those pieces are in place only then can you start using a language to evoke the necessary responses from the target computer.

All this assumes you are building a tutorial for beginners rather than experienced programmers. If you leave out the above steps you have to make the assumption that the people you are talking to already know how to "program" just not necessarily how to construct a solution in the target computer language.

Concepts like loops, comparisons, variables, data structures, conditionals then have to be introduced in the target computer language. At that point you start putting together the concepts of real mode debugging, stepwise refinement, and rapid prototyping.
If you leave any of this out you leave behind people who may want to use AutoHotkey but have none of the basics to realize that desire.

Yes, I have taught computer languages before. And the big lesson I learned from teaching was it's as much about why something is done as it is how to do it. And I haven't even mentioned until now the need to construct salient examples and exercises needed to illustrate the points outlined above.

#15 bruno

bruno
  • Members
  • 161 posts

Posted 05 April 2011 - 05:19 AM

Thanks for your great effort and dedication to the forum. I look forward to your ongoing and future contribution to AHK, gaming, and the field of computing. :lol: