Any tricks to pre-select menu item?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Any tricks to pre-select menu item?

Post by bdeshi »

Any way to pre-select/pre-focus a scripted menu item so that ENTER triggers it?
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Any tricks to pre-select menu item?

Post 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:

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Any tricks to pre-select menu item?

Post by bdeshi »

Clever but... I can use it but it's not very enduser-friendly... @Don, perhaps an additional caption flag: 8 = pre-select.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 4398
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Any tricks to pre-select menu item?

Post 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. :)

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Any tricks to pre-select menu item?

Post 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:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 4398
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Any tricks to pre-select menu item?

Post 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".

admin
Site Admin
Posts: 65026
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Any tricks to pre-select menu item?

Post by admin »

I don't know of a way to preselect an item in a popup menu.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Any tricks to pre-select menu item?

Post by bdeshi »

d'oh!
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 4398
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Any tricks to pre-select menu item?

Post 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

admin
Site Admin
Posts: 65026
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Any tricks to pre-select menu item?

Post by admin »

Yes, exactly.

admin
Site Admin
Posts: 65026
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Any tricks to pre-select menu item?

Post by admin »

BTW, comet landing now live here: https://new.livestream.com/ESA/cometlanding

klownboy
Posts: 4398
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Any tricks to pre-select menu item?

Post by klownboy »

Cool...they did it! :appl:

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Any tricks to pre-select menu item?

Post 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';

Post Reply