But if the focus is on textboxFilterAD and I press Enter, the $comboPCName_KeyPress function is executed instead of $textboxFilterAD_KeyPress like I wish.
Is there something I can do to have the correct function called when I press Enter, depending on the selected control?
This is more of a .NET forms question, not really Powershell, but my assumption is that the Enter (and Esc) button have a separate events happening for AcceptButton. You may be able to even make it work more ‘as designed’ if you use the onFocus() event to set the AcceptButton to the required control rather than using KeyPress to change it. If you look at the second link, they are setting the AcceptButton and not parsing KeyPress events, but regardless you should be searching for .NET forms forums to find your answer if the below doesn’t work for you.