Summary: Learn to use the OK and Cancel buttons in a Windows PowerShell GUI.
How can I use Windows PowerShell to get my GUI’s OK and Cancel buttons to trigger when
the user presses ENTER or Escape?
Assign the OK and Cancel button objects to your form’s AcceptButton and CancelButton properties:
$form.AcceptButton = $OKButton
$form.CancelButton = $CancelButton