Page 1 of 1

Any tricks to pre-select menu item?

Posted: 12 Nov 2014 14:24
by bdeshi
Any way to pre-select/pre-focus a scripted menu item so that ENTER triggers it?

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 15:00
by TheQwerty
Not on "Enter" only, but if you don't mind running the script on Escape and loss of focus as well you can abuse _Terminate like so:

Code: Select all

"_Initialize" Global $RAN_SCRIPT = false;

"A"
  Global $RAN_SCRIPT = true;
  Echo "A";

"B"
  Global $RAN_SCRIPT = true;
  Echo "B";

"_Terminate"
  Global $RAN_SCRIPT;
  if (! $RAN_SCRIPT) {
    if (Confirm('No script selected! Run A?')) {
      Sub 'A';
    }
  }

  // Actual terminate stuff.
  Echo 'Terminate';
Alternately you might be able to do something with wait and sendkeys in _Initialize but I shudder at the thought. :naughty:

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 15:19
by bdeshi
Clever but... I can use it but it's not very enduser-friendly... @Don, perhaps an additional caption flag: 8 = pre-select.

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 15:25
by klownboy
Sammay, an option for pre-focus and run on enter would be a nice idea for scripted menus and would probably be well-used. Don, maybe instead of one of used "states" (e.g. Bold, Checked, Disabled), like the very seldom used "checked" or a new state, could be a default to act as execute on "hitting "Enter".

TheQwerty, nice idea! By the way, your method also works to run the designated program if you click anywhere outside the menu since that's essentially the same as hitting escape. Typically though the since you've just clicked on a CTB or what ever to bring up the menu, clicking again outside the menu shouldn't be a big a deal as hitting escape. :appl: I suppose it could be a real annoyance it you actually decided not to un the program after bringing up the menu, you click outside the menu or hit escape, and the set-up default runs anyway. :)

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 15:42
by bdeshi
klownboy wrote:Don, maybe instead of one of used "states" (e.g. Bold, Checked, Disabled), like the very seldom used "checked" or a new state, could be a default to act as execute on hitting "Enter".
Not just that - the caption must also be focused so users know hitting Enter is going to trigger that.
it could be a real annoyance it you actually
decided not to run the program after bringing up the menu, you click outside the
menu or hit escape, and the set-up default runs anyway.
Yep. Just found out first-hand. :cool:

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 15:51
by klownboy
SammaySarkar wrote:the caption must also be focused so users know hitting Enter is going to trigger that
So maybe the "preselect" would have the bold highlighted option built-in. As it is now the bold option can only be used for one menu item. If it would be combined with the new state (e.g., "8"), the menu option is bolded and also "preselected" to run on hitting enter. And, as it is currently with "bold", obviously only one item could be "preselected".

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 16:28
by admin
I don't know of a way to preselect an item in a popup menu.

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 16:33
by bdeshi
d'oh!

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 16:44
by klownboy
Hi Don, just to make sure we're on the same page, we were referring to scripted menus not popupmenu. Currently the help file states...

Code: Select all

"Caption|Icon|State : Label" Script
 where
State Default = 1
State Checked = 2
State Disabled = 4
Currently, the "default" which is the bolded menu item, is already recognized and flagged by XY. Are you saying, there's no way to make that bolded (default) menu item execute on enter? Thanks,
Ken

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 16:47
by admin
Yes, exactly.

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 16:51
by admin
BTW, comet landing now live here: https://new.livestream.com/ESA/cometlanding

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 17:12
by klownboy
Cool...they did it! :appl:

Re: Any tricks to pre-select menu item?

Posted: 12 Nov 2014 17:23
by TheQwerty
SammaySarkar wrote:Clever but... I can use it but it's not very enduser-friendly...
If you make "A" the default item ("A||1") so that it is bold it's better.
klownboy wrote: By the way, your method also works to run the designated program if you click anywhere outside the menu since that's essentially the same as hitting escape.
I know... :P
TheQwerty wrote: if you don't mind running the script on Escape and loss of focus as well
This is also why I added the Confirm right before posting. ;)

----

Alternately, you can bypass XY showing the menu entirely and instead show your own "menu" using InputSelect. If you make sure the default script is the first item in the list and enable style 32 it will be automatically selected.

Code: Select all

"Show Menu"
  $res = InputSelect(,'A|B|C',, 32+64);

  End $res == '',, true;
  Sub '_' . $res;

"- : _-" //---------------------------------------------------------------------

"_A"  Echo 'A';

"_B"  Echo 'B';

"_C"  Echo 'C';

EDIT: And I hate it but it seems to work:

Code: Select all

"_Initialize"
  SendKeys '{Down}';

"A||1" Echo 'A';

"B"  Echo 'B';

"C"  Echo 'C';