KeyDown Event not firing on Form level

0
0

Hello,

I am encountering an issue with handling key values using the KeyDown event on a Window in my Wisej web application. Specifically, I am trying to capture key presses globally (at the form level), but the KeyDown event does not seem to catch or handle the key inputs as expected. No matter which control has focus, I want the event to fire. Is this intended?

I have provided simple code that tries to handle the KeyDown event on the form level and print the key value to the debug console. I have tested the exact same code in Windows Forms and it worked there just fine. The application has a few TextBox and ComboBox controls.

Attachment
  • You must to post comments
0
0

Hi Robert,

actually my last comment was not entirely correct as there is a way using the KeyPreview property.

See attached sample.

Best regards
Frank

  • You must to post comments
0
0

I just encountered exactly the same issue; my question too is how to capture Keypress events in a form regardless of which control is focused. In a simple test application, the KeyDown event works as expected when no controls are placed on the form, but as soon as a single button is placed, the event is not fired any more. Sorry when I don’t understand the concept here – thanks for a quick hint! Best regards, Robert

  • Frank (ITG)
    Hi Robert, as written by Alaa, events are not propagated to the container. Depending on your needs you might want to use Accelerators to handle specific keys. Best regards, Frank
  • Robert Langer
    Hi Frank, Accelerators was exactly the solution for me! Works like a charm! Thanks!
  • You must to post comments
0
0

Hello Alaa,

Thank you for your previous response. I understand now that key events like KeyDown and KeyUp don’t propagate to the container by default.

Though I would still like to capture KeyDown events globally at the form level for a specific use case: I need to handle input from a barcode scanner. The scanner is configured to send a sequence of characters with a prefix and suffix that identify the input as coming from the scanner. I want to capture this entire sequence at the form level, regardless of which control has focus (e.g., TextBox, ComboBox, etc.). I could attach an event handler to a KeyDown event for every control, but this approach seems inefficient, since it would be difficult to maintain in an app with many controls.

How can I capture KeyDown events globally in Wisej.NET, so that I can detect and process the characters coming from the barcode scanner (including its configured prefix and suffix)?

Thank you.

Best regards,
Zan.

  • You must to post comments
0
0

Hi Zan,

The KeyUp and KeyDown events don’t propagate to the container, what you’re experiencing is the correct behavior in Wisej.NET!

Best Regards,

Alaa

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.