diff --git a/ohos-project/entry/src/main/ets/pages/Index.ets b/ohos-project/entry/src/main/ets/pages/Index.ets index de1507d975cf2899cab11da5accc77923fe25701..974ec6bae8d8ae13abf53858e7b94350f820d920 100644 --- a/ohos-project/entry/src/main/ets/pages/Index.ets +++ b/ohos-project/entry/src/main/ets/pages/Index.ets @@ -51,7 +51,8 @@ struct Index { type: CommonConstants.XCOMPONENT_TYPE, libraryname: CommonConstants.XCOMPONENT_LIBRARY_NAME }) - + .focusable(true) + .defaultFocus(true) } .width(CommonConstants.FULL_PARENT) .height(CommonConstants.FULL_PARENT) diff --git a/src/core/ohos/SDL_ohos_xcomponent.cpp b/src/core/ohos/SDL_ohos_xcomponent.cpp index ae2932a351c9d64b85369209d1851c5716399a2e..dd322a8d52a74773ddaf1a0227939b599d600b75 100644 --- a/src/core/ohos/SDL_ohos_xcomponent.cpp +++ b/src/core/ohos/SDL_ohos_xcomponent.cpp @@ -38,6 +38,7 @@ extern "C" { #include "../../video/ohos/SDL_ohosvideo.h" #include "../../video/ohos/SDL_ohostouch.h" #include "../../video/ohos/SDL_ohosmouse.h" +#include "../../video/ohos/SDL_ohoskeyboard.h" #ifdef __cplusplus } #endif @@ -141,7 +142,9 @@ onKeyEvent(OH_NativeXComponent *component, void *window) OH_NativeXComponent_GetKeyEventCode(keyEvent, &code); if (OH_NATIVEXCOMPONENT_KEY_ACTION_DOWN == action) { + OHOS_OnKeyDown(code); } else if (OH_NATIVEXCOMPONENT_KEY_ACTION_UP == action) { + OHOS_OnKeyUp(code); } } }