Any tricks to pre-select menu item?
Any tricks to pre-select menu item?
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 ]
[ this user is asleep ]
Re: Any tricks to pre-select menu item?
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:
Alternately you might be able to do something with wait and sendkeys in _Initialize but I shudder at the thought. 
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';Re: Any tricks to pre-select menu item?
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 ]
[ 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?
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.
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. 
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.
Re: Any tricks to pre-select menu item?
Not just that - the caption must also be focused so users know hitting Enter is going to trigger that.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".
Yep. Just found out first-hand. :cool: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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ 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?
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".SammaySarkar wrote:the caption must also be focused so users know hitting Enter is going to trigger that
-
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?
I don't know of a way to preselect an item in a popup menu.
FAQ | XY News RSS | XY X
Re: Any tricks to pre-select menu item?
d'oh!
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ 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?
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... 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
Code: Select all
"Caption|Icon|State : Label" Script
where
State Default = 1
State Checked = 2
State Disabled = 4
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?
BTW, comet landing now live here: https://new.livestream.com/ESA/cometlanding
FAQ | XY News RSS | XY X
-
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?
Cool...they did it! 
Re: Any tricks to pre-select menu item?
If you make "A" the default item ("A||1") so that it is bold it's better.SammaySarkar wrote:Clever but... I can use it but it's not very enduser-friendly...
I know...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.
This is also why I added the Confirm right before posting.TheQwerty wrote: if you don't mind running the script on Escape and loss of focus as well
----
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';
XYplorer Beta Club