Jump to content

Scan for an image


Recommended Posts

I started macroing earlier this year on Quick Macros which I think is a great program focusing and dedicated solely to macroing. Autoit is in a different and way superior league and I switched immediately once I discovered it. The main reason was QM could not be compiled (their new beta now includes compiling but I'm not sure on the size or what is included in the file). Anyway I'm hooked on Autoit despite some of the features that I wish would improve and I'm sure will in time. Autoit assumes everyone knows how to program while QM first explains in detail with the assumption that everyone is a newbie idiot before they start getting technical. I am looking for a function similar to "scan" in QM and I've read most of the forums (I think) and can't understand why a similar function does not exist in Autoit? If it does please direct me.

Why do I want it? Unless there is another way I am looking at a menu that does not return any of the items listed. I want to know if an item exists on this menu. I was thinking of "scanning" with a .bmp image of the listed item.

I've pasted an extract from QM's help below:

------

Find image on screen

Syntax

int scan(file [window] [rect] [flags])

Parts

file - bitmap (.bmp) or icon (.ico and other) file that contains the image to search for. It also can be handle (if numeric), or exe resource id (if begins with semicolon, e.g. ":1" or ":2 file.bmp"). If used handle, scan does not destroy the bitmap or icon.

window - top-level or child window, in which to search. Can be omitted or 0 (constant).

rect - variable of type RECT. Can be used to limit the search region. When scan returns, contains the location of the found image. Default: 0.

flags - combination of the following values. Default: 0.

1 Move the mouse pointer to the image.

2 Generate error if image not found.

4 Use the top-left pixel color of the image as transparent color.

16 Search only in the client area. If rect specifies the search region, it must be relative to the client area. This flag is used only if window is used.

32 When file is icon file, use large icon (32x32). Default - small icon (16x16).

64 If file is handle or resource, use this flag to specify that it is icon.

Remarks

Searches for an image on the screen. Returns 1 if found, 0 if not (or throws error if flag 2 is set). If flag 1 is used, moves the mouse pointer to the found image. If rect is used, populates the variable with the screen coordinates of the found image.

-------

Link to comment
Share on other sites

I started macroing earlier this year on Quick Macros which I think is a great program focusing and dedicated solely to macroing. Autoit is in a different and way superior league and I switched immediately once I discovered it. The main reason was QM could not be compiled (their new beta now includes compiling but I'm not sure on the size or what is included in the file). Anyway I'm hooked on Autoit despite some of the features that I wish would improve and I'm sure will in time. Autoit assumes everyone knows how to program while QM first explains in detail with the assumption that everyone is a newbie idiot before they start getting technical. I am looking for a function similar to "scan" in QM and I've read most of the forums (I think) and can't understand why a similar function does not exist in Autoit? If it does please direct me.

Why do I want it? Unless there is another way I am looking at a menu that does not return any of the items listed. I want to know if an item exists on this menu. I was thinking of "scanning" with a .bmp image of the listed item.

I've pasted an extract from QM's help below:

------

Find image on screen

Syntax

int scan(file [window] [rect] [flags])

Parts

file - bitmap (.bmp) or icon (.ico and other) file that contains the image to search for. It also can be handle (if numeric), or exe resource id (if begins with semicolon, e.g. ":1" or ":2 file.bmp"). If used handle, scan does not destroy the bitmap or icon.

window - top-level or child window, in which to search. Can be omitted or 0 (constant).

rect - variable of type RECT. Can be used to limit the search region. When scan returns, contains the location of the found image. Default: 0.

flags - combination of the following values. Default: 0.

1 Move the mouse pointer to the image.

2 Generate error if image not found.

4 Use the top-left pixel color of the image as transparent color.

16 Search only in the client area. If rect specifies the search region, it must be relative to the client area. This flag is used only if window is used.

32 When file is icon file, use large icon (32x32). Default - small icon (16x16).

64 If file is handle or resource, use this flag to specify that it is icon.

Remarks

Searches for an image on the screen. Returns 1 if found, 0 if not (or throws error if flag 2 is set). If flag 1 is used, moves the mouse pointer to the found image. If rect is used, populates the variable with the screen coordinates of the found image.

-------

What are you trying to do?

If you are trying to manipulate IE pages, there are a huge number if IE functions in the newest beta version of AutoIt.

Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain

Link to comment
Share on other sites

No not IE pages. QuickBooks - but it could also apply be Excel etc. To repeat why I want it:

I am looking at a menu that does not return any of the items listed. I want to know if an item exists on this menu. I was thinking of "scanning" with a .bmp image of the listed item. In other words capture the menu containing the item, then croping down to the item only and saving in item.bmp - then scan the menu with item.bmp.

Link to comment
Share on other sites

No response from anyone and having gone through all the forums yet again I see no easy answer to this everyday macroing problem. So took another look at QuickMacros and you don't need to scan for a bmp match on menus. They have an accessible object function and all menu items are returned. Autoit might be superior in some things but not in macroing I guess. Going to give QM a second try.

Link to comment
Share on other sites

  • Moderators

No response from anyone and having gone through all the forums yet again I see no easy answer to this everyday macroing problem. So took another look at QuickMacros and you don't need to scan for a bmp match on menus. They have an accessible object function and all menu items are returned. Autoit might be superior in some things but not in macroing I guess. Going to give QM a second try.

Don't really know how to take that one. Did you bother to try any of the Object oriented options have before you jump(ed) the gun?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Don't really know how to take that one. Did you bother to try any of the Object oriented options have before you jump(ed) the gun?

Okay SmOke_N don't get mad at me but I'm back after a day of bending my mind with QM. I can't go back, I've learned too much Autoit. If anyone can put me out of my misery, you can, but when I read one of your OCR forums yesterday I figured I was doomed. The other program makes it so easy for people like me with scan and acc. One line and its all done and with Autoit nobody is even chatting about it (in open forum). Nobody pointed me to object oriented options. Im not sure which options you are referring? Ive mentioned before that I learn best from example. Please show me (and everyone else).

1)How can I view objects and see tree views of menubars menuitems menupopups etc. Oleviewer does not show these items (does it)? I couldn't figure it out. Let's use Notepad as an example again please.

2) How do I test if a menu item exists in an object?

Okay I did not jump ship and Im sorry for even mentioning the other program but they do make this so easy. I know you can do it (you've probably done it) - Ill never be able to figure it out unless you show me in an example. You are the best (except for that OCR stuff you wrote that freaked me out). You also do great work when I get you mad at me.

Link to comment
Share on other sites

  • Moderators

I see a bit of manipulation in you wording... nice :P .

What OCR stuff "freaked" you out? I'm fairly blunt when it comes to talking about it.

There is a tool if you read the COM stuff that you can download and use, it has a link to it in the help file, that gives you the object information your looking for.

http://download.microsoft.com/download/2/f...2235/ovi386.exe

I also suggest looking at Object/COM Reference in the help file.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I see a bit of manipulation in you wording... nice :) .

What OCR stuff "freaked" you out? I'm fairly blunt when it comes to talking about it.

There is a tool if you read the COM stuff that you can download and use, it has a link to it in the help file, that gives you the object information your looking for.

http://download.microsoft.com/download/2/f...2235/ovi386.exe

I also suggest looking at Object/COM Reference in the help file.

I told you Ive already downloaded that Oleviewer and it does not shown menuitems. I read the COM stuff and basically I'm supposed to read the COM bible or something before continuing and then the syntax of the described methods/properties are in C/C++ style. Give me a break. In the example it says go to Control but I guess that was an earlier version - now there are 3 kinds of controls but no control. I can't find notepad. I could not find menuitems in the given IE example either. Okay so lets assume Ive ObjGet(notepad.exe) how do I retrieve the menuitems? I cant find any examples. Please dont make me beg but I will if I have to.

The OCR thing I looked at it again and I still did not understand but Ill keep trying until I do. I originally thought oh no, not more systems stuff to learn until someone finally writes PixelInPixel() or is it PixelGetPos() or just Scan(). Autoit seems to intentionally make life difficult for high level macroing and its not right. These basic and essential tools should have been in place years ago. Autoit could become the ultimate tool. Autoit could become the greatest program ever produced as long as their goal continues to be power to the people. The best dental program can only be written by dentists. Laugh but its true. You must provide people with the tools and not yourselves. Everyone will be using Au3ObjInfo soon right? In the mean time please help me retrieve the objects menuitems.

Me manipulate you never? Seriously you have to help me here please. Please dont just fluff me off again.

Link to comment
Share on other sites

  • Moderators

I told you Ive already downloaded that Oleviewer and it does not shown menuitems. I read the COM stuff and basically I'm supposed to read the COM bible or something before continuing and then the syntax of the described methods/properties are in C/C++ style. Give me a break. In the example it says go to Control but I guess that was an earlier version - now there are 3 kinds of controls but no control. I can't find notepad. I could not find menuitems in the given IE example either. Okay so lets assume Ive ObjGet(notepad.exe) how do I retrieve the menuitems? I cant find any examples. Please dont make me beg but I will if I have to.

The OCR thing I looked at it again and I still did not understand but Ill keep trying until I do. I originally thought oh no, not more systems stuff to learn until someone finally writes PixelInPixel() or is it PixelGetPos() or just Scan(). Autoit seems to intentionally make life difficult for high level macroing and its not right. These basic and essential tools should have been in place years ago. Autoit could become the ultimate tool. Autoit could become the greatest program ever produced as long as their goal continues to be power to the people. The best dental program can only be written by dentists. Laugh but its true. You must provide people with the tools and not yourselves. Everyone will be using Au3ObjInfo soon right? In the mean time please help me retrieve the objects menuitems.

Me manipulate you never? Seriously you have to help me here please. Please dont just fluff me off again.

1. Seperating your text makes it easier to read (I only read bits and pieces of what you write, because I get lost in the text if I'm tired).

2. It's not AutoIt's "Job" to do anything, we are a community, if you need a function like that, learn the tools and write it, then donate it to autoit... where do you think half of the functions came from? ... Users just like you and I that needed something that wasn't provided, and made a UDF to do it, then showed it as a community.

Me manipulate you never? Seriously you have to help me here please. Please dont just fluff me off again.

3. I don't have to do anything. If me not putting off my own projects to hold your hand through it is considered by you a fluff, the considered yourself fluffed once again.

You need to catch me on a day that I post 20+ support suggestions, that's when I have to time to "possibly" care about your issues... but until then, if you don't like how "primal" autoit is, then find a language that does everything you want and more, otherwise those types of comments I could personally do without... AutoIt is all that it is and nothing more until we as community make it more than it is.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

this reads a bit like a JFK speech. (Ask not what AutoIt can do for you... but what you can do for AutoIt.)

Lar.

I thought that is what I'm doing. Its frustrating. I can't do what you guys do so my contribution is - here I am a CA (like CPA) and I want to scan and access objects. Why can't I? Autoit can do all these other fantastic things at my level and other programs can do this at my level. I don't want to program with Autoit, I want to macro with Autoit. I'll show Autoit great macros and how to macro better if it provides me with the tools okay. The first Autoit macro I wrote I am giving away for free at www.CAfirm.net - its a great macro and I'm trying in the true Autoit spirit to giving more power to the people in my field of accounting. If you are saying you that you only accept input from C++ programmers then I'm sorry I bothered you guys.
Link to comment
Share on other sites

If you need to recognize something on screen.. look for my PixelAreaRecord and PixelAreaFind... one takes a snapshot and saves it in an INI... the other reads that INI and finds the area you told it to... no matter where it is on screen.

http://www.autoitscript.com/forum/index.ph...st&p=134394

Thanks I'll check it out but this was my original question which changed once I discovered my approach was wrong. Instead of messy pulling up a menu and scanning if menuitem exists in pixels, I can go straight to the object and read it. Unfortunately I'm asked to read the COM bible and learn C++ to access objects. Please Larry just show me an example and I will take it from there. Please open notepad and read the menus for me. I can do this easily (simple drag and drop) but not in Autoit. I can't find Autoit examples anywhere.
Link to comment
Share on other sites

Standard menus (notepad) can use menu functions. There is a whole bunch of MenuGetItem() type functions written. When I get to work I will look for them. If it is not a standard menu (a control that looks like a menu e.g MS Word) then it is more complicated.

Lar.

Thanks Larry it works perfectly returning all the details on the first menu item. I'm going to study this later today until I completely understand it. Once understood, I'll try it on a couple of accounting programs and I hope you don't mind but I'll be back if they are not standard menus. I truly appreciate this.

PS could you please give me a hint which variable I need to change to get details on the second menu item, if not I will figure it out eventually.

Link to comment
Share on other sites

$submenu = GetSubMenu($menu_hwnd,0)

would be

$submenu = GetSubMenu($menu_hwnd,1)

for the second item...

LAr.

I figured it out before I read this. Fantastic now to test it elsewhere. Thanks.

Edit 1

It works everywhere so far Wow fantastic. So what was all that COM stuff about – is this what is used for nonstandard menus?

Thank you Thank you Thank you. Brilliant.

Edited by 1905russell
Link to comment
Share on other sites

  • 1 month later...

Granted it's probably just me seeing how I didn't sleep a wink lastnight,but for the life of me I can't make the PixelAreaRecord and the PixelAreaFind into one fully working script.It's not a big deal or anything,but I was just tired of all the open tabs in scite and i'm also trying to learn from larry's example/scripts and it's tedious switching back and forth.Yes I renamed the variables that would conflict with eachother and edited the tooltips but other than that I don't see where/what is stopping it from working correctly.Anywho if anyone has any ideas or has already accomplished the same thing maybe you could give me a few pointers.Try not to be too brutal as i'm at most an idiot on good days and today is not a good day. :lmao:

Link to comment
Share on other sites

Thanks a bunch larry,it's times like this I wonder if some steps got skipped when I was made,you know kinda like those little lego kits,the box shows a car and I manage to make a plain with one wing shorter than the other.Anywho thanks again and for creating and maintaining this language.

P.S. I'm fairly sure most of the above is misspelled,sadly english is my first and only language,i'm just stupid...stupid and tired wich is a dangerous combination. :lmao:

Link to comment
Share on other sites

Well I have a few current projects and one is basically some web automation wich ive done fairly succsesfully but thought If I could learn enough to understand the above code maybe I could make it a bit better.I'm sure theres alot of more appropriate methods that could/should replace pixelsearch and the like but for people such as myself it's just the easiest starting point.So in short my point in this thread was nothing more than to see exactly how franks above code works and then why I couldn't get the two into one script,but now I can look at it for hours and scratch my head until I figure it out or get miffed and do something else until my heads clears up a bit. :lmao:

Edit:Oh and if you meant what i'm trying to do next,after I figure this out i'm gonna look into a way to list multiple results,meaning it'll return the x,y of each found,not just the first found.It'll be tough but i'll figure it out sooner or later and actually although this will be of use in one project it's just part of my "Find an AutoIt project to keep you busy and learn from in the process".

Edited by fry
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...