Question

For a certain inputform, I'd like to make it possible to do input with the keyboard. I know how to read the keys through KeyPressed and KeyUp, but the problem is that when a control has got the focus and the user presses the Enter key, that control receives the a Click event. Is it possible to prevent that behaviour ? Or is it possible to know if a Click Event was fired by the mouse or by the keyboard ?

Was it helpful?

Solution

Does this help? From Microsoft Knowledge Base

Move the Button's code from the button.Click() to a button.MouseClick()

OTHER TIPS

This would be easier if you could describe the situation and exact behaviour you want... :)

You can set:

Form.KeyPreview = True

This sends Key Events to the Form first, and then to the Control. This gives you the opportunity to catch Key Events on the form and 'cancel' them:

e.Handled = True

More info

Also make sure you haven't set the AcceptButton for the Form!

You can also listen for keyboard events and filter out keys.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top