From: S-Y. Chen on
On Dec 14, 12:25 am, APN <palm...(a)yahoo.com> wrote:
> On Dec 13, 9:08 pm, "S-Y. Chen" <shenyeh_c...(a)hotmail.com> wrote:
>
>
>
> > On Dec 13, 1:20 am, APN <palm...(a)yahoo.com> wrote:
>
> > > Here is short sample to start notepad and open the file dialog
>
> > > (myappdir) 67 % set pid [exec notepad.exe &]
> > > 1212
> > > (myappdir) 68 % ::twapi::find_windows -pids [list $pid] -text
> > > "Untitled - Notepad" -toplevel true
> > > 0x140524
> > > (myappdir) 69 % twapi::set_focus 0x140524 ; twapi::send_keys
> > > {%FOabc.txt{ENTER}}
> > > 22
>
> > > (basically sending Alt-F O accelerator followed by name of file and
> > > ENTER. See documentation of send_keys for key syntax (follows Visual
> > > Basic syntax for keystrokes). If you can do the whole thing with
> > > keyboard accelerators, you might try something similar.
>
> > > For an example of painting with a mouse seehttp://wiki.tcl.tk/20231
>
> > > However, as others have said, DO NOT USE THIS METHOD. Unless the
> > > sequence really short and simple, , this way lies madness.
>
> > > You might try Auto-It for something like this. I have not used it
> > > extensively but I think it does more under the covers to block other
> > > input, verify the correct windows have focus etc. With TWAPI, you have
> > > to do that work yourself using lower level commands.
>
> > > /Ashok
>
> > Ashok
>
> > Well this helps a lot. I will begin from there. Thanks a lot !!
>
> > By the way, is there a way to locate the position of a specific text
> > (string) on the menu in a window (for example, those File, Edit,
> > Draw........etc on the menu bar), and then move the mouse there ?
>
> > The reason I have to do this, is, well, you may not believe it, but
> > many of these packages do not even have a short cut key.......
>
> > Thanks again
>
> > Regards
> > S-Y. Chen
>
> Moving the mouse is easy, use move_mouse :-) but finding the
> individual text string, not sure how you would do that other than
> trying it out (and then hope no one changes system font sizes!)
>
> /Ashok


Well, I am just thinking that if those captions on the menu (like
"File", "Edit", etc.) can be "searched" and "located" or "found" as a
string through TWAPI, maybe it will be easier for me to locate the
menu position in a more general case. (maybe not ?). If it can be
"searched" and "located" as a string, there is nothing to do with the
font size right ?

I am just afraid that, the position of the menu may change from
machine to machine, and I just need to do it in a machine independent
fashion.


Anyway, is it possible to do that ?

Regards
S-Y. Chen








From: Helmut Giese on
Hi,
I had good success in the past using cwind (http://wiki.tcl.tk/5019).
It has an easy to use syntax:
lsearch -glob [cwind::wlist] *Paint
will search the title bars of all existing windows for '*Paint' and
will return -1 if not found - meaning 'MS Paint' is not running.

If not found
exec $::env(COMSPEC) /c start mspaint.exe &
after 500
cwind::waitwind {*Paint}
will start and wait for it.

You send keys like
cwind::send foo
or
cwind::send |CTRL+| v |CTRL-|
for something like <Ctrl v>.

This said, you can surely achieve the same with twapi.

Some thoughts on the subject, though:
- I would at all cost try to avoid the use of the mouse. If at all, it
should only ever be needed to open a top menu. Once it is open you can
use the cursor keys to move inside the menu or into a sub-menu.
- _If_ you need the mouse to open a menu, maximize the app's window
first (send Alt <space> to open the system menu, then the appropriate
key to maximize it) - then you know at least approximately where the
menu bar is.
- Beware of users who use non-standard system font sizes. People with
poor eye sight will use a larger font, meaning that many items on the
screen are bigger than standard (younger people may use a smaller
font) - another argument against using the mouse.
- Check regularly whether the app you want to control is still on top
(maybe an email notification popped up?).
- For every app you want to control create configuration data
describing in some way the menu entries of interest - e.g. which
sequence of keys are necessary to get there (like DOWN DOWN DOWN LEFT
DOWN RET to activate the 2nd entry of a certain sub-menu).
- If creating files erase them first if they already exist. Else it
will work the first time and fail afterwards because the app pops up a
'Do you want to overwrite this file?' type of dialog.
- Probably more things to consider which I forgot ...

Good luck
Helmut Giese
From: S-Y. Chen on
Thanks for all the good advise. I guess I will need some time to try
out and digest all of them.

Thanks again !

Regards
S-Y. Chen