Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

Handling Custom Input

Open blobotic opened this issue 3 years ago • 2 comments

Hi, first off, this is a great project!

I've been searching for a way to handle custom text input, specifically keyboard input when you're not focused on any particular widget.

For example, if I have a couple of text boxes (say, nk_edit_string) stacked vertically, I'd like for a new one to be created, appended to the top, and focused on on keyboard input if there is nothing currently active, otherwise handle input in the active widget (i.e. if I press "e" with nothing focused, I want to see a new nk_edit_string at the top of my window with an "e" in its buffer).

I am aware of nk_item_is_any_active, so I've been bashing my head trying to figure out how to handle input otherwise.

I'm currently using the d3d11 demo as a base, and I have

MSG msg;
nk_input_begin(ctx);
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
    if (msg.message == WM_QUIT) running = 0;
    else if (msg.message == WM_KEYDOWN) nk_input_key(ctx, msg.wParam, 1);
    else if (msg.message == WM_KEYUP) nk_input_key(ctx, msg.wParam, 0);
    TranslateMessage(&msg);
    DispatchMessageW(&msg);
}
nk_input_end(ctx);

, but I'm stuck on what to do after nk_input_key.

Any help would be greatly appreciated!

blobotic avatar Sep 03 '21 03:09 blobotic

That's correct, though you'll want to port the msg.wParam to a enum nk_keys.

RobLoach avatar Apr 19 '24 14:04 RobLoach

I'm facing a similar issue. Is it then reasonable/expected to extend nk_keys for other cases that it doesn't include, e.g. ascii letters, function keys, ...?

bolt-blue avatar Jun 25 '24 12:06 bolt-blue