Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trigger macro for controls on a window
#1
Hi Gintaras, hi all

I'd like to make automation for a program, and i got all the main routines triggered by hotkeys.

BUT, is it possible from QM to act when a given control is clicked?

Say there is a edit box in program main interface, can QM trigger an action when I click in it?

Thanks
#2
If it's an accessible object, try accessible object trigger.

example
Macro Macro2365
Trigger $a 133 -4 "" "Edit" 1001 "" "#32770" "Font" 42 "" "Font style:"     Help - how to add the trigger to the macro
Code:
Copy      Help
;\
function hwnd idObject idChild
Acc a.FromEvent(hwnd idObject idChild)
;out a.Name
out a.Value
Runs when in a Font dialog focused "Font style" edit control.
Read more about the trigger in QM help.
#3
Or create a function that is always running when the window is active. Let it repeatedly wait for mouse left button, and on click get object from mouse...
#4
Ok, will try..

for second option, i already have a toolbar linked to the program main window.

Is it possible to use the toolbar to achieve the goal?
#5
Better in other thread. It could have the same window trigger as the toolbar.

Function detect_mouse_clicks_in_window_58736
Trigger !a"- WordPad" "WordPadClass"     Help - how to add the trigger to the macro
Code:
Copy      Help
int hwnd=TriggerWindow

rep
,wait 0 ML
,if(!IsWindow(hwnd)) ret
,if(win!hwnd) continue
,Acc a.FromMouse; err continue
,str name=a.Name; err continue
,out name
,
#6
the first with hook seems to work, must adapt it, so i'll g=have some more questions coming i believe..

Thanks
#7
ok, first thing is I must filter on role, and get value to act upon.

I searched in the docs, is there a table correspondance for role converting number value to actual name, as done by the "find accessible object" window?
#8
Table - look in MSDN library.
Function - don't remember, look in the source code, it's in the System folder.
#9
ok
#10
ok, controls are in constant position in window.

what's the fastest way to implement so click position linked to an action, something like a range routine...

a derivate from

if(PtInRect(&r f.x f.y))

but with an iteration from rect array (or something like that).

rectangle 1 0 0 100 100
rectangle2 10 10 100 100

foreach rec rectangle
if( PtInRect(&rec f.x f.y))
do action based on rectangle mouse points to..

don't know if it is clear...
#11
Macro Macro2368
Code:
Copy      Help
ARRAY(RECT) a
SetRect &a[] 0 0 100 100
SetRect &a[] 100 100 200 200
;...

int i
for i 0 a.len
,RECT& r=a[i]
,outRECT r
,;if(PtInRect(&r f.x f.y))
,,;out 1
Function outRECT
Code:
Copy      Help
;/
function RECT&r

out "L=%i T=%i R=%i B=%i   W=%i H=%i" r.left r.top r.right r.bottom r.right-r.left r.bottom-r.top
#12
What is exactly zRECT then??? can't find something about it in QM
#13
Updated. Now outRECT. Use to debug-output RECT variables.
#14
hmmm seems to be the way to go.

does QM makes available a tool to have the rect coordinates of an item in a window (directly x,y,width and height), or must it be programmed???
#15
A tool to record UI object from mouse rectangles and create code like this?
SetRect &a[] 0 0 100 100
SetRect &a[] 100 100 200 200
#16
nope, a code to get directly dimensions (width & height) and position (x & y) of an element, in client window coordinates for x & y
#17
Quote:A tool to record UI object from mouse rectangles and create code like this?
SetRect &a[] 0 0 100 100
SetRect &a[] 100 100 200 200

sorry, i misread, it's indeed the same thing
#18
Macro Record UI object rectangle
Trigger F7     Help - how to add the trigger to the macro
Code:
Copy      Help
Acc a.FromMouse
int x y w h
a.Location(x y w h) ;;get screen coord of the object
RECT r; SetRect &r x y x+w y+h ;;convert to RECT

OnScreenRect 1 r; 0.5; OnScreenRect 2 r ;;remove this if don't need to show the rectangle

int hwnd=GetAncestor(a.Hwnd 2) ;;get top-level parent window
MapWindowPoints 0 hwnd +&r 2 ;;screen to client

out F"SetRect &a[91]] {r.left} {r.top} {r.right} {r.bottom}"

err+
#19
perfect....
#20
ldarrambide Wrote:ok, first thing is I must filter on role, and get value to act upon.

I searched in the docs, is there a table correspondance for role converting number value to actual name, as done by the "find accessible object" window?

Maybe you need this?
Code:
Copy      Help
Acc a.FromMouse
;...
str role
a.Role(role)
out role
sel role
,case "PUSHBUTTON"
,;...
#21
that is what i use, but an array with number<->text would be easier as I could use an osd with the role directly then
by mapping nulber to text..less tedious to code
#22
See how Acc.Role gets text from number.

Acc a.Role ;;press F2 on Role
#23
ok, where is my error here???
Function detect_mouse_clicks_in_window_58736
Code:
Copy      Help
function hwndTB
;int hwndOwner=GetToolbarOwner(hwndTB)
ARRAY(RECT) a
SetRect &a[] 110 77 403 96
SetRect &a[] 110 229 403 248
SetRect &a[] 411 252 516 277
SetRect &a[] 411 283 516 308
SetRect &a[] 411 314 516 339
SetRect &a[] 595 41 612 58
SetRect &a[] 587 43 770 348
SetRect &a[] 595 251 700 276
SetRect &a[] 595 283 700 308
SetRect &a[] 595 315 700 340


int x y
rep
,wait 0 ML
,if(!IsWindow(hwndTB)) ret
,if(win!hwndTB) continue
,Acc b.FromMouse; err continue
,POINT p; xm(p 0 1) ;;get mouse position into p.x and p.y
,sub.InRect(a hwndTB p.x p.y)
,;out name

#sub InRect
function ARRAY(RECT)&a int'u int'x int'y
int i
for i 0 a.len
,RECT& r=a[i]
,;outRECT r
,if(PtInRect(&r x y))
,,out 1


never output 1...
grrrrr
#24
xm(p 0 1) gets coordinates in screen, not in hwndOwner.
SetRect cordinates are probably in hwndOwner.
#25
yes that was it, changing

POINT p; xm(p 0 1)

to

POINT p; xm(p hwndTB 1)

did it
#26
anyway, something is wrong because it outputs 1 only when mouse left clicks in first rectangle of array...
#27
Is hwndTB the correct window? In my deleted example it was toolbar handle.
#28
yes, it's the window handle of the owner of the toolbar...

toolbar for program window
Function ToolbarHook543986
Code:
Copy      Help
;/
function# hWnd message wParam lParam

;<help #IDH_EXTOOLBAR>Toolbar hook help</help>

;OutWinMsg message wParam lParam ;;uncomment to see received messages
int hwndOwner=GetToolbarOwner(hWnd)
#29
ok, for unknow reason the use of the control dimension did wrong, it's working now with correct numbers..

sorry
#30
ok, now just to tune : is it possible to do an action when a certain object is clicked, the freeze the rep loop while the action is processed, and then make rep again
functional after?


ex:

rep
do monitor
do monitor
action found ---------------------> freeze rep (this one) ----------> do action -------------------> rep starts again

is using a function on action found is enough to stop/restart the rep loop?


Forum Jump:


Users browsing this thread: 1 Guest(s)