11-07-2010, 10:45 AM
To automate popup menus, usually we use key, or mouse commands.
Alternative ways
(I think, 4 is the best answer to your question)
1. Record menu commands.
To record, click menu Tools -> Record Menu.
This is the most reliable way. But not all menus can be recorded.
2. Acessible objects.
Macro Macro1478
However it will be more difficult with submenus.
Also, not all menus support accessible objects.
Also, requires more code and more time to create macro.
Therefore I think that better is to use keyboard. Unless it is impossible to make reliable.
3. Keyboard. To pass keycodes to function, use ARRAY(KEYEVENT).
key currently does not accept key codes as variables.
But there is other way to pass keycodes to a function.
If called as function, key does not press keys, but instead returns array of key events.
The array can be passed to a function that interprets them as it wants.
Function SendKeysToWindow simplifies it: pasting to notepad (when notepad is in background)
example
Macro Macro1487
function example
Function rClkStentor
4. Keyboard. To pass keycodes to function, let the function call RunTextAsFunction or RunTextAsFunction2.
function example
Function rClkStentor
Alternative ways
(I think, 4 is the best answer to your question)
1. Record menu commands.
To record, click menu Tools -> Record Menu.
This is the most reliable way. But not all menus can be recorded.
2. Acessible objects.
Macro Macro1478
;This macro clicks menu item "Refresh" in popup menu of desktop.
rig 200 100 ;;right click desktop
int w1=wait(10 WV "+#32768") ;;wait for popup menu
Acc a=acc("Refresh" "MENUITEM" w1 "" "" 0x1001) ;;get menu item object
a.DoDefaultAction ;;click
mou ;;return mouse
;To capture popup menu items:
;;;In 'Find Accessible Object' dialog, right click "Drag" icon, and click "Capture when Shift pressed".
;;;Invoke the popup menu, move mouse to the item, and press Shift.
However it will be more difficult with submenus.
Also, not all menus support accessible objects.
Also, requires more code and more time to create macro.
Therefore I think that better is to use keyboard. Unless it is impossible to make reliable.
3. Keyboard. To pass keycodes to function, use ARRAY(KEYEVENT).
key currently does not accept key codes as variables.
But there is other way to pass keycodes to a function.
If called as function, key does not press keys, but instead returns array of key events.
The array can be passed to a function that interprets them as it wants.
Function SendKeysToWindow simplifies it: pasting to notepad (when notepad is in background)
example
Macro Macro1487
rig 200 100 ;;right click desktop
int w1=wait(10 WV "+#32768") ;;wait for popup menu
SendKeysToWindow w1 key(DDD) ;;press Down arrow 3 times
function example
Function rClkStentor
;/
function ARRAY(KEYEVENT)'a
;Right clicks, waits for popup menu, and presses keys.
;Error if fails.
;EXAMPLE
;mou 200 100
;rClkStentor key(DDRDY)
spe -1
POINT p; xm(p)
;int m=getmonitor(p);
;if (m=3) or (m=4)
,rig p.x p.y
,int w1=wait(10 WV "+#32768") ;;wait for popup menu
,SendKeysToWindow w1 a ;;press keys
err end _error
4. Keyboard. To pass keycodes to function, let the function call RunTextAsFunction or RunTextAsFunction2.
function example
Function rClkStentor
;/
function $keycodes
;Right clicks, waits for popup menu, and presses keys.
;Error if fails.
;EXAMPLE
;mou 200 100
;rClkStentor "DDRDY"
spe -1
POINT p; xm(p)
;int m=getmonitor(p);
;if (m=3) or (m=4)
,rig p.x p.y
,int w1=wait(10 WV "+#32768") ;;wait for popup menu
,wait 0 H RunTextAsFunction(F"spe {getopt(speed)}[]key {keycodes}") ;;press keys
err end _error