Repeated KeyDownEvent Trigger with KeyCode = 0

Hello everyone,

I’m encountering an issue with handling keyboard events in my Unity project using UI Toolkit. My KeyDownEvent handler is triggered twice upon a single key press. The first call occurs with the correct KeyCode matching the pressed key, but it is immediately followed by a second call where the KeyCode is 0.

Here is how I register the event handler:

_uiRoot.focusable = true;
_uiRoot.Focus();
_uiRoot.RegisterCallback<KeyDownEvent>(OnKeyDown);

My OnKeyDown method looks like this:

private void OnKeyDown(KeyDownEvent evt)
{
    Debug.Log($"KeyCode: {evt.keyCode}, target: {evt.target}, type={evt.eventTypeId}");
}

The log outputs the following:

KeyCode: 49, target: TemplateContainer UIDocument-container (x:0.00, y:0.00, width:822.40, height:371.20), type=13
KeyCode: 0, target: TemplateContainer UIDocument-container (x:0.00, y:0.00, width:822.40, height:371.20), type=13

I understand that KeyCode.None (which is 0) might indicate a system event, but I’m unsure why it’s triggered right after a regular key press event. This happens every time, and I can’t find the reason. Checking other UI controls did not reveal any elements that could be intercepting or duplicating keyboard events.

Could anyone suggest why this is happening and how to fix it? Perhaps someone has faced a similar issue or has suggestions for resolving this error.

Thanks in advance for any help!