Use keypress to trigger script

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 9 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Use keypress to trigger script

Post by daviesg6 »

I have created a form with multiple PowerShell scripts available to the user (primarily searches for AD objects). Each of these has the option to run and display on screen or export to file via buttons.

I would like to improve this by allowing users the option to hit a key (enter for example) to run the script. Is there a way I can do this? I know it is possible to use this option if there is a single button, but I can't work out how to do this for multiple options.

Is there a way to do this :?:
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Use keypress to trigger script

Post by jvierra »

There can only be one default action per form. The enter key is assigned to the defined default.

You can handle all keys and detect the enter key and have it do anything you want but it has to be hand coded.
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Use keypress to trigger script

Post by daviesg6 »

jvierra wrote:There can only be one default action per form. The enter key is assigned to the defined default.

You can handle all keys and detect the enter key and have it do anything you want but it has to be hand coded.
Thanks, kind of figured that was the case but wanted confirmation. I'll leave it so the users have to use the mouse to hit the button they want to use.
This topic is 9 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked