Consider a XAML TextBox in Win Phone 7.
<TextBox x:Name="UserNumber" />
The goal here is that when the user presses the Enter
button on the on-screen keyboard, that would kick off some logic to refresh the content on the screen.
I'd like to have an event raised specifically for Enter
. Is this possible?
Enter
on each keypress? i.e. some analog to ASCII 13?Check the event. And the following JavaScript code to detect whether the Enter key is pressed: const input = document. querySelector("input"); input. addEventListener("keyup", (event) => { if (event.
You can use the Panel. DefaultButton property to automatically click a button when the user presses Enter. If you don't want to show the button, you can set its style="display: none" . This is the best solution IMO.
The keyIsDown() function checks if the key is currently down, i.e. pressed.
A straight forward approach for this in a textbox is
private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { Debug.WriteLine("Enter"); } }
You'll be looking to implement the KeyDown event specific to that textbox, and checking the KeyEventArgs for the actual Key pressed (and if it matches Key.Enter, do something)
<TextBox Name="Box" InputScope="Text" KeyDown="Box_KeyDown"></TextBox> private void Box_KeyDown(object sender, KeyEventArgs e) { if (e.Key.Equals(Key.Enter)) { //Do something } }
Just a note that in the Beta version of the WP7 emulator, although using the software on-screen keyboard detects the Enter key correctly, if you're using the hardware keyboard (activated by pressing Pause/Break), the Enter key seems to come through as Key.Unknown - or at least, it was doing so on my computer...
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