Japanese Keyboard input

BlitzMax Forums/BlitzMax Programming/Japanese Keyboard input

Grey Alien(Posted 2009) [#1]
Hi all, as a follow on from this old thread: http://www.blitzmax.com/Community/posts.php?topic=69361 I now need to make Unwell Mel accept Kana characters when the player enters their name.

I already have a font with all those characters in the correct unicode "slots" and that works fine for displaying text.

My problem is that when I switch to Japanese keyboard and use MS IME and then use GetChar() I am getting Integers in the range of 180-200ish which is nowhere near the 12300ish I was expecting.

Does anyone know why? Perhaps it's because the char codes being sent are in UTF-8? If so does anyone have a quick function to convert UTF-8 to UTF-16?

Many thanks in advance!


jkrankie(Posted 2009) [#2]
I'd be interested in knowing this too.

Cheers
Charlie


Tommo(Posted 2009) [#3]
Windows ime send the characters in there native codec.
You can use Win Api to convert it.
Here is the code I used for get chinese input.

Works with japanese input, but GetChar seems to fail to capture some chararcter, maybe it's because I'm not using a Japanese code page.


Extern "win32"
	Function MultiByteToWideChar:Int (page:Int, flags:Int, src:Byte Ptr, srclen:Int, dst:Short Ptr, dstlen:Int)

	Function WideCharToMultiByte:Int (page:Int, flags:Int,  ..
			src:Byte Ptr, srclen:Int, dst:Short Ptr, dstlen:Int,  ..
			defaultchar:String, fusedefault:Byte Ptr)

End Extern

Graphics 640, 480, 0


SetBlend ALPHABLEND
SetImageFont(LoadImageFont("c:/windows/fonts/msmincho.ttc", 25, 0))


Local s:String = ""
Local k:Int = 0
While Not KeyHit(KEY_ESCAPE)
	
	s = ConvertUnicode(GetChars()) 
	
	If s <> Null
		DrawText s, k, 0
		k:+s.Length * 25
	End If
	
	PollEvent() 
	Flip
Wend


Function GetChars:Byte[] () 
	Local b:Byte[4096] 
	Local b1:Byte
	Local n:Int = 0
	Repeat
		b1 = GetChar()
		b[n] = b1
		n:+1
	Until b1 = 0
	Return b
End Function


Function ConvertUnicode:String(str:Byte[], l:Int = -1, code:Int = 0) 'code for windows code page, 0 for system native
	Global output:Short[2048] 
	MultiByteToWideChar(code, 0, str, l, output, 4096)
	Return String.Fromwstring(output).Trim() 
End Function




Grey Alien(Posted 2009) [#4]
Thanks for this, I tried it with CodePage 932 and it seemed to work when I was using a plain Japanese keyboard but when I tried using IME it started to fail, shame. I may have to abort this.


Dreamora(Posted 2009) [#5]
at least BM does not straight crash anymore like Blitz3D / BlitzPlus the moment an onscreen keyboard / touch pen goes active ... There is at least hope to find a way to solve it.