Showing posts with label Accessible Objects. Show all posts
Showing posts with label Accessible Objects. Show all posts

Thursday, June 21, 2007

Lesson 6: Getting Stuck in the GUI Hacks

Getting Stuck in the GUI Hacks
GUI hacks are the processes that you have to create because you can't get at the option or method of doing something to/in a program. For example, a really ugly GUI Hack would be
  1. open Windows Explorer
  2. hit Alt-d and put in the directory you want to go to
  3. then hitting 'Tab' three times to get to the file list
  4. use the 'key' command to start spelling the name of the file you want so that it is selected
  5. type Ctl-c
  6. hit Alt-d to move to the address bar and put in the new directory
  7. hit 'Tab' three times to get to the file list
  8. hit Ctl-v

Of course no one would do this; that's what 'ren' or 'cop' is for but sometimes you just have to interact with program GUI dialogs. And God help me, I HATE GUI HACKS! There are just so many more things that can go wrong so many 'edge-cases' you have to account for...God help me but I hate them. Well, if you gotta you gotta so here's some ideas that might help.

Timing is everything in GUI hacking. If the dialog is slow to open, or if the field you need inside the dialog is slow to be drawn, or if...blah blah blah. The first thing I do to make sure my GUI hacks are going to work is put in 'wait's everywhere so that the macro 'paces' itself. Here's an example of that. Sometimes when I send emails via Outlook, I don't want a 'message receipt' nor do I want to keep a copy of the sent message, so I have a macro that changes the message property for me and then sends it. Here's what the dialog looks like.



As you can see, there are two check boxes I want to deselect; they can either be 'clicked' by the mouse (I find this less reliable for various reasons) or the values of the check boxes can be inverted by using keystrokes (Alt-r and Alt-n). First things first; I have to get the dialog to show up. I do that by using the "Accessible object actions" item in the "Windows, controls" button on the QM toolbar and drag the aiming reticle on top of the "Options..." button on the message I'm currently writing. This method works well enough but ask yourself what would happen if the toolbar that had that "Options..." button wasn't visible at the time; the macro would fail immediately (and so would my willowy grasp on sanity). I'd prefer a keyboard shortcut but I don't have one for it, so I make due. But now, I have to guess how long to wait for the dialog to show up before I start hitting my keystrokes....or do I?....Nope. Here's what I do.
0 WA "Message Options"
This is a version of the 'wait' command. The '0' tells QM to wait indefinitely for the window with the name "Message Options" to become 'active' ('WA'=wait till active). I pulled the window name directly from the QM Editor itself. When you have the editor open the status bar continually gives you information on both the cursor position and the window that it is currently hovering over. The window name is in the first row and comes just after the mouse position relative to the window. So now, when I start the macro, it 'clicks' the "Options..." button and waits for the dialog to become active; it then sends the keystrokes for the above check boxes and hits 'enter'. It then waits for the message itself to become active so that it can send the 'Send Message' command via an Alt-s keystroke.
spe 50
Acc option_a=acc("Options..." "DROPLIST" win(".*Message" "OpusApp" "" 0x200) "MsoCommandBar" "" 0x1001)
option_a.Mouse(1)
0 WA "Message Options"
'Ar
'An
'Y
0 WA "Message"
'As

Now you may ask about the second line from the bottom and say, "Gordon Bennett, not ALL your emails can be tittled 'Message'!"...ok, so maybe you wouldn't say that but someone did....probably.....might have....well, ok they could have said it give me that at least.... Well, this kind of gets into the 'win' function which I should cover another time in depth but let's suffice it to say that, it is case sensitive and can be anywhere within the window name. Here's what my window's tittle bar actually looks like with a standard message.
There it is; a macro with built rest stops (but smells better) for when you just 'have' to GUI hack.

So have at it and I'll see you next time cause the hook always brings you back.

Monday, May 14, 2007

Lesson 5: The Extra Mile

Ok, so there's more than one way to skin a cat and there's more than just a few ways to get text into a window. This next method is much more complicated but hang with me; if I can do it, I think you will be able to as well.

Go to the "Windows, controls" icon on the QM Toolbar and go down to the "Accessible object actions" menu choice. This opens up a dialog that looks like this:



Take a look at all the different actions on the left-hand side. These will really start to open up your possibilities as you get more and more skilled at QM (or as some say, 'more kung-fu'). In this lesson, I'm just going to be dealing with the 'Get value' and the 'Set value'.

Let's start with a text editor of your choice; I'm going to use Notepad but you can use anything you like. First, let's set the value of a window/field or whatever you are wanting to change. Click on 'Set value' and then click-and-hold the 'Drag' icon; drag it over and drop it on the part of the window for which you want to set the value.



You'll notice that there is a thick black line surrounding the parts of the window as you hover over them. Let go of the mouse button when you have selected the right part of the window. QM now shows you what it 'sees' of that area.
Most of the time, you'll need to modify the 'Window' title; you can do that by clicking the button with three dots right next to it. You'll see this dialog after doing so.

The first thing I usually do is start adding wildcards to the Title. So, '- Notepad' becomes '*- Notepad'. Don't forget to also check the 'Use *' checkbox below! There are other options you can modify but I rarely have to.

There are also other values you can change in the main dialog too but I'll not be covering that in this lesson. So, now my dialog looks like this:

You can change the variable assignment if you wish within this dialog before letting QM enter this info into the macro. Now, hit 'Ok' and it puts this info into your macro.
Acc a=acc("" "TEXT" win("*- Notepad" "Notepad" "" 0x3) "Edit" "" 0x1800 0x0 0x20000040)
a.SetValue("Hey, set this value.")
Now that we have a target, let's start putting in the info. As you can see, the second line of my code is already doing just that. I can also have it set the value using a variable as well. Now, the thing to keep in mind about this function is that it will erase anything that is there already....unless......
_s=a.Value();;this, of course, gets the value
_s.from(_s "[]Now it's both values")
a.SetValue(_s)
Yep, that's just what we were looking for. Now, you can 'append' info to the window by feeding its value back into a variable and manipulating than variable. You may not want to use this technique for more than small dialog fields but who knows, it may be just the thing you're looking for in that hard to get-at window.

So have at it and I'll see you next time cause the hook always brings you back.