Skip to content

Commit dc28e96

Browse files
committed
Harmony port: keyboard event
1 parent 9e61fcb commit dc28e96

File tree

3 files changed

+3184
-1
lines changed

3 files changed

+3184
-1
lines changed

src/core/ohos/SDL_ohos.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <ace/xcomponent/native_interface_xcomponent.h>
1010
#include "../../video/ohos/SDL_ohosvideo.h"
1111
#include "SDL3/SDL_mutex.h"
12+
#include "../../video/ohos/SDL_ohoskeyboard.h"
1213

1314
OHNativeWindow *nativeWindow;
1415
SDL_Mutex *g_ohosPageMutex = NULL;
@@ -99,7 +100,32 @@ static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window)
99100
}
100101
#endif
101102
}
102-
static void onKeyEvent(OH_NativeXComponent *component, void *window) {}
103+
static void onKeyEvent(OH_NativeXComponent *component, void *window)
104+
{
105+
OH_NativeXComponent_KeyEvent *keyEvent = NULL;
106+
if (OH_NativeXComponent_GetKeyEvent(component, &keyEvent) >= 0)
107+
{
108+
OH_NativeXComponent_KeyAction action;
109+
OH_NativeXComponent_KeyCode code;
110+
OH_NativeXComponent_EventSourceType sourceType;
111+
112+
OH_NativeXComponent_GetKeyEventAction(keyEvent, &action);
113+
OH_NativeXComponent_GetKeyEventCode(keyEvent, &code);
114+
OH_NativeXComponent_GetKeyEventSourceType(keyEvent, &sourceType);
115+
116+
if (sourceType == OH_NATIVEXCOMPONENT_SOURCE_TYPE_KEYBOARD)
117+
{
118+
if (OH_NATIVEXCOMPONENT_KEY_ACTION_DOWN == action)
119+
{
120+
OHOS_OnKeyDown(code);
121+
}
122+
else if (OH_NATIVEXCOMPONENT_KEY_ACTION_UP == action)
123+
{
124+
OHOS_OnKeyUp(code);
125+
}
126+
}
127+
}
128+
}
103129
static void onNativeTouch(OH_NativeXComponent *component, void *window) {}
104130
static void onNativeMouse(OH_NativeXComponent *component, void *window) {}
105131
static void OnDispatchTouchEventCB(OH_NativeXComponent *component, void *window) {}

0 commit comments

Comments
 (0)