0 registered members (),
1,209
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
inkey and Unicode
#470699
01/31/18 11:07
01/31/18 11:07
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Hello! I've been trying to implement Unicode keyboard input in my regular lite-C Pure game. Using on_message I receive WM_CHAR events, including characters sent by a Japanese IME thing for testing. However, it seems like I cannot convert those to actual Unicode characters (the lParam is just 1 which probably is not right for any subsequent ToUnicode calls...?). I assume this might be because IsWindowUnicode(hWnd) returns 0 and WM_CHAR messages are transformed to ANSI before they are sent to the application. I've thought about creating my own hWnd with RegisterClassExW (which is not supported in GStudio8/include/windows.h, only RegisterClassEx, so maybe via a DLL) but I couldn't figure that one out yet. Would that be the right way?
Alternatively, I've tried to call SetWindowsHookEx(WH_KEYBOARD_LL, HookCallback, NULL, 0); in a DLL or directly in lite-C, then do the Unicode translation there and send the Unicode characters to the engine. However, it seems like the callback function is not triggered correctly, in particular no response to/ from IME input. WH_KEYBOARD_LL may or may not be the wrong HookID but I did not have luck with any other mode.
Do you have any advice? Thanks for reading.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: inkey and Unicode
[Re: Superku]
#470707
01/31/18 21:42
01/31/18 21:42
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
I gave it a shot and jap. IME does indeed not trigger KEYDOWN events. You might need some other functions to retrieve IME text since it's not really a key press/release but a string of characters that's sent to the window.
POTATO-MAN saves the day! - Random
|
|
|
Re: inkey and Unicode
[Re: Kartoffel]
#470731
02/03/18 17:26
02/03/18 17:26
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Yes, the hook is destroying the inputs. (EDIT: Oh, and thanks for giving it a shot!)
I've created a new Unicode hWnd window with the same/ default on_message engine message loop. That one is receiving the same messages as the default engine window, so the issue must be somewhere else (in the message loop itself?).
I don't think I can do this on my own. Mr. Lotter, do you have any advice?
Thanks.
Last edited by Superku; 02/03/18 17:36.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: inkey and Unicode
[Re: Superku]
#472242
04/17/18 22:30
04/17/18 22:30
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
So you never actually catch a WM_UNICHAR message, only WM_CHAR? https://msdn.microsoft.com/de-de/library/windows/desktop/ms646288(v=vs.85).aspx See comment concerning wParam: The Unicode DefWindowProc posts a WM_CHAR message with the same parameters and the ANSI DefWindowProc function posts either one or two WM_CHAR messages with the corresponding ANSI character(s). Sounds like what is happening to you. Then you could build your own inkeyw based on custom message handling.
#include <acknex.h>
#include <windows.h>
LRESULT CALLBACK OriginalHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MyMessageHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (WM_UNICHAR == message)
{
printf("OMG it's Unicode!");
return 0;
}
return OriginalHandler(hwnd,message,wParam,lParam);
}
function main()
{
OriginalHandler = on_message; // store the original message loop
on_message = MyMessageHandler; // and replace it by your own
...
}
Last edited by Firoball; 04/17/18 22:45.
|
|
|
Re: inkey and Unicode
[Re: FBL]
#472285
04/18/18 16:56
04/18/18 16:56
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Thanks for the suggestion, I actually hadn't found WM_UNICHAR yet, always only looked at WM_CHAR or non-filtered input. :-X However, I cannot seem to trigger WM_UNICHAR at all. I found WM_IME_CHAR which gets fired N times before N characters from an IME arrive, however they are converted to ANSI as far as I can tell before I get my dirty fingers on them. Even when I CreateWindowExW() a new Unicode window (IsWindowUnicode() returns 1 then) I cannot extract or combine WM_CHAR events into unicode digits.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|