Basically, I want to be able to trigger an event when the ENTER key is pressed. I tried this already:
private void input_KeyDown(object sender, KeyEventArgs e) { if (e.Equals("{ENTER}")) { MessageBox.Show("Pressed enter."); } }
But the MessageBox never shows up. How can I do this?
To check if an “enter” key is pressed inside a textbox, just bind the keypress() to the textbox. $('#textbox'). keypress(function(event){ var keycode = (event.
You can execute a function by pressing the enter key in a field using the key event in JavaScript. If the user presses the button use the keydown to get know its enter button or not. If it enters the key then call the JavaScript function.
The keyup event occurs when a keyboard key is released.
Give this a shot...
private void input_KeyDown(object sender, KeyEventArgs e) { if(e.KeyData == Keys.Enter) { MessageBox.Show("Pressed enter."); } }
To add to @Willy David Jr answer: you also can use actual Key codes.
private void input_KeyDown(object sender, KeyEventArgs e) { if (e.KeyChar == 13) { MessageBox.Show("Pressed enter."); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With