Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
special keys as function arguments
#1
I wrote this simple macro that right clicks the screen to bring up a pop-up menu, then navigates using the up/down/right arrows to get to the desired command:

POINT p; xm(p); ym(p);
int m=getmonitor(p);
if (m=3) or (m=4) ;;if monitor 3 or 4, click to bring out pop-up menu
rig p.x p.y
key UUUUURY

Trouble is, I'm writing the same code 20 times because I have different commands in the pop-up menu I want to call up quickly. So I wanted to make the above code into a function "rClkStentor" and pass a string with the command of where to move:

/
function lpstr's

POINT p; xm(p); ym(p);
int m=getmonitor(p);
if (m=3) or (m=4)
rig p.x p.y
key(s)

Which I then called as rClkStentor("UUUUURY"), rClkStentor("DDDRDY"), etc.

That has failed miserably. I think it's trying to actually type the string characters rather than the special key commands (the arrow keys). Is there a simple way to convert "s" back to special keys to use in the key command?

On a related topic, is this the most logical way of dealing with a pop-up menu within a program? I've been doing this because the objects within the pop-up menu do not appear to be accesible, i.e. when I go click on QM to drag the crosshairs to the pop-up menu it de-selects the pop-up and it's gone. Is there an easier way? Ideally, you'd want a way of grabbing elements in a pop-menu that didn't require a fixed order of the items in the menu.
#2
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
Code:
Copy      Help
;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
Code:
Copy      Help
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
Code:
Copy      Help
;/
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
Code:
Copy      Help
;/
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


Forum Jump:


Users browsing this thread: 1 Guest(s)