Skip to content

Commit 8378cba

Browse files
authored
ogc: add USB keyboard support (#68)
1 parent 4f26b2b commit 8378cba

File tree

5 files changed

+97
-2
lines changed

5 files changed

+97
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2944,7 +2944,7 @@ elseif(OGC)
29442944
endif()
29452945
list(APPEND EXTRA_LDFLAGS "${OGC_ARCH_SETTINGS} ${OGC_LINKER_FLAGS}")
29462946
if(NINTENDO_WII)
2947-
list(APPEND EXTRA_LIBS "wiiuse;bte")
2947+
list(APPEND EXTRA_LIBS "wiiuse;bte;wiikeyboard")
29482948
endif()
29492949
list(APPEND EXTRA_LIBS "ogc;m")
29502950
endif()

src/main/wii/SDL_wii_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
7373
WPAD_SetVRes(WPAD_CHAN_ALL, 640, 480);
7474

7575
MOUSE_Init();
76-
// TODO KEYBOARD_Init(NULL);
76+
KEYBOARD_Init(NULL);
7777
fatInitDefault();
7878

7979
/* Call the user's main function. Make sure that argv contains at least one

src/video/ogc/SDL_ogcevents.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "../../events/SDL_events_c.h"
2828

2929
#include "SDL_ogcevents_c.h"
30+
#include "SDL_ogckeyboard.h"
3031
#include "SDL_ogcmouse.h"
3132
#include "SDL_ogcvideo.h"
3233

@@ -99,6 +100,7 @@ void OGC_PumpEvents(_THIS)
99100

100101
#ifdef __wii__
101102
pump_ir_events(_this);
103+
OGC_PumpKeyboardEvents(_this);
102104
#endif
103105
}
104106

src/video/ogc/SDL_ogckeyboard.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
#include "SDL_ogckeyboard.h"
22+
#include "../../events/SDL_keyboard_c.h"
23+
24+
#if defined(SDL_VIDEO_DRIVER_OGC) && defined(__wii__)
25+
#include <gctypes.h>
26+
#include <wiikeyboard/keyboard.h>
27+
28+
void OGC_PumpKeyboardEvents(_THIS) {
29+
keyboard_event ke;
30+
31+
s32 res = KEYBOARD_GetEvent(&ke);
32+
if (res && (ke.type == KEYBOARD_RELEASED || ke.type == KEYBOARD_PRESSED)) {
33+
SDL_SendKeyboardKey((ke.type == KEYBOARD_PRESSED) ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)ke.keycode);
34+
35+
if (ke.type == KEYBOARD_PRESSED) {
36+
const Uint16 symbol = ke.symbol;
37+
char utf8[4] = {'\0'};
38+
39+
/* ignore private symbols, used by wiikeyboard for special keys */
40+
if ((symbol >= 0xE000 && symbol <= 0xF8FF) || symbol == 0xFFFF)
41+
return;
42+
43+
/* convert UCS-2 to UTF-8 */
44+
if (symbol < 0x80) {
45+
utf8[0] = symbol;
46+
} else if (symbol < 0x800) {
47+
utf8[0] = 0xC0 | (symbol >> 6);
48+
utf8[1] = 0x80 | (symbol & 0x3F);
49+
} else {
50+
utf8[0] = 0xE0 | (symbol >> 12);
51+
utf8[1] = 0x80 | ((symbol >> 6) & 0x3F);
52+
utf8[2] = 0x80 | (symbol & 0x3F);
53+
}
54+
55+
SDL_SendKeyboardText(utf8);
56+
}
57+
}
58+
}
59+
#endif

src/video/ogc/SDL_ogckeyboard.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
22+
#ifndef SDL_OGC_keyboard_h_
23+
#define SDL_OGC_keyboard_h_
24+
25+
#include "../../SDL_internal.h"
26+
#include "SDL_ogcvideo.h"
27+
28+
#ifdef __wii__
29+
void OGC_PumpKeyboardEvents(_THIS);
30+
#endif
31+
32+
#endif /* SDL_OGC_keyboard_h_ */
33+
34+
/* vi: set ts=4 sw=4 expandtab: */

0 commit comments

Comments
 (0)