ultralight-ux / Ultralight

Lightweight, high-performance HTML renderer for game and app developers.
https://ultralig.ht
4.66k stars 195 forks source link

ulViewFireKeyEvent Documentation/help #503

Open jeff8j opened 5 months ago

jeff8j commented 5 months ago

I cant seem to get a keypress working with the CAPI

I am trying to trigger a "e" keycode 69 in js keypress and release

when creating the key event with ulCreateKeyEvent do i put 69 as the virtual_key_code or the native_key_code? what do I put for the ULString text and unmodified_text should I create a blank ULString?

adamjs commented 5 months ago

Are you synthesizing the key presses yourself or translating them from an existing framework?

I would actually look at Sample 7, specifically where it takes GLFW keypress (WindowGLFW_key_callback) and GLFW char events (WindowGLFW_char_callback) and translates them into appropriate Ultralight events for guidance on using this API: https://github.com/ultralight-ux/Ultralight/blob/master/samples/Sample%207%20-%20OpenGL%20Integration/src/Window.cpp

jeff8j commented 5 months ago

At the moment I am trying to synthesize the input to get it working, the end result will come from sdl This is my keydown code I trigger it with the sdl keydown then trigger the up when releases I have tried various keycode/scancode/text combos and cant get anything to work at all I load a js key tester page to make sure its not my js https://keyjs.dev/ and it gets nothing as well

int keycode = 69; // 101;
int scancode = 8;
ULString keytext = ulCreateString("E");

ULKeyEvent evt = ulCreateKeyEvent(kKeyEventType_RawKeyDown, 0, keycode, scancode, keytext, keytext, false, false, false);
ulViewFireKeyEvent(view, evt);
ulDestroyKeyEvent(evt);
jeff8j commented 5 months ago

I pulled out the relevant code from my program and made a small program that has the same problem https://github.com/jeff8j/Ultralight-SDL-Key-Test/blob/main/main.cpp