Hitting the Enter Key

Jan 21, 2014 at 12:20 AM
I searched and couldn't find a way so that when I enter text into a text box and hit enter i can run something and use the text entered. Is there a way to do this.

Jan 21, 2014 at 4:35 AM
The simplest thing is to use a button set to -IsDefault so that when you hit enter the button gets pressed and you can handle the -On_Click ... otherwise you'd have to handle the keydown or keyup events and filter the character, which is a pain :)

Something like this would work:
Grid -ControlName 'Your Information' -Columns Auto,* -Rows *,20 -MinWidth 250 -Margin 4 {
    Label "Command"
    New-TextBox -Name "Command" -Column 1
    New-Button "Run" -IsDefault -Width 100 -Height 20 -On_Click {
        Get-ParentControl | Set-UIValue -PassThru | Close-Control
    } -Row 1 -Column 1
} -Show -On_Loaded { $Command.Focus() }
Jan 21, 2014 at 4:58 PM
Perfect thank you. This will keep my fingers off the dreaded mouse.