I am writing a game on windows using SDL. Since the game need support the
language of Double-byte coding (chinese character with IME), so the method
of using SDL_Keydown could not workable. So I decided to patch SDL to
deliver WM_CHAR message of Windows.
static int DX5_CheckInput(_THIS, int timeout, BOOL processInput)
{
MSG msg;
int i;
HRESULT result;
DWORD event;
/* Check the normal windows queue (highest preference) */
posted = 0;
while ( ! posted &&
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) {
if ( GetMessage(&msg, NULL, 0, 0) > 0 ) {
-
TranslateMessage( &msg ); // generate WM_CHAR message DispatchMessage(&msg);
…
LRESULT DX5_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM
lParam)
{
- char b;
- char tmps[2];
- FILE *f;
switch (msg) {
- case WM_CHAR:
- b=wParam;
- tmps[0]=b;
- tmps[1]=0;
- SDL_mutexP(KB);
- f=fopen(“c:\sdl.log”,“a”);
- fprintf(f,“got: %s\n”,tmps);
- fclose(f);
- SDL_mutexV(KB);
- break;
#ifdef WM_ACTIVATEAPP
case WM_ACTIVATEAPP: {
int i, active;
active = (wParam && (GetForegroundWindow() == hwnd));
…
After pached, SDL could get the input of ASCII and IME successfully now. But
new question emerged, that a few WM_CHAR messages would lost randomly, for
example, while input the string like 1234567890, it might get 234567890 or
134567890. What’s the reason for that?
Thanks a lot.