| 
		
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		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
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		If it's an accessible object, try accessible object trigger. 
example 
Macro Macro2365 
Trigger $a 133 -4 "" "Edit" 1001 "" "#32770" "Font" 42 "" "Font style:"   ;\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.
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		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...
	 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		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?
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		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"   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
 ,
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		the first with hook seems to work, must adapt it, so i'll g=have some more questions coming i believe..
 Thanks
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		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?
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		Table - look in MSDN library.Function - don't remember, look in the source code, it's in the System folder.
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		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...
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		Macro Macro2368 ARRAY(RECT) aSetRect &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 ;/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
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		What is exactly zRECT then??? can't find something about it in QM
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		Updated. Now outRECT. Use to debug-output RECT variables.
	 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		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???
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		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
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		nope, a code to get directly dimensions (width & height) and position (x & y) of an element, in client window coordinates for x & y
	 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		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
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		Macro Record UI object rectangle 
Trigger F7   Acc a.FromMouseint 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+
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		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?
 Acc a.FromMouse;...
 str role
 a.Role(role)
 out role
 sel role
 ,case "PUSHBUTTON"
 ,;...
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		that is what i use, but an array with number<->text would be easier as I could use an osd with the role directly thenby mapping nulber to text..less tedious to code
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		See how Acc.Role gets text from number.
 Acc a.Role ;;press F2 on Role
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		ok, where is my error here??? 
Function detect_mouse_clicks_in_window_58736 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
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		xm(p 0 1) gets coordinates in screen, not in hwndOwner.SetRect  cordinates are probably in hwndOwner.
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		yes that was it, changing 
 POINT p; xm(p 0 1)
 
 to
 
 POINT p; xm(p hwndTB 1)
 
 did it
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		anyway, something is wrong because it outputs 1 only when mouse left clicks in first rectangle of array...
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		Is hwndTB the correct window? In my deleted example it was toolbar handle.
	 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		yes, it's the window handle of the owner of the toolbar... 
toolbar for program window 
Function ToolbarHook543986 ;/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)
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		ok, for unknow reason the use of the control dimension did wrong, it's working now with correct numbers..
 sorry
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		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?
 |