# IME漢字入力ウィンドウ v0.1 # https://cycr.net/ # # $game_system.inputで呼び出し # 【使用例】 # スクリプト:$game_actors[1].name = $game_system.input class Game_System def input char_max = 16 ri = Win32API.new("kernel32", "GetPrivateProfileStringA", "pppplp", "l") fw = Win32API.new("user32", "FindWindowA", "pp", "l") gwr = Win32API.new("user32", "GetWindowRect", "pp", "l") gwl = Win32API.new("user32", "GetWindowLong", "pp", "l") cw = Win32API.new("user32", "CreateWindowEx", "ippiiiiipppp", "i") gwt = Win32API.new("user32", "GetWindowText", "ppi", "l") swl = Win32API.new("user32", "SetWindowLong", "pil", "l") sm = Win32API.new("user32", "SendMessage", "pipp", "v") sf = Win32API.new("user32", "SetFocus", "p", "v") gf = Win32API.new("user32", "GetFocus", "v", "l") gks = Win32API.new("user32", "GetKeyState", "i", "i") gc = Win32API.new("Imm32", "ImmGetContext", "p", "i") ss = Win32API.new("Imm32", "ImmSetOpenStatus", "pi", "v") buf = "\0" * 256 ri.call("Game", "Title", "", buf, 255, ".\\Game.ini") game_window = fw.call("RGSS Player", buf) buf = "\0" * 256 gwr.call(game_window, buf) rect = buf.unpack("I!4") x = (rect[0] + rect[2] - 320) / 2 y = (rect[1] + rect[3] - 128) / 2 hi = gwl.call(game_window, -6) $name_window = cw.call(0x10080, "BUTTON", encode("名前を入力してください", 65001, 0), 0x12000001, x, y, 320, 128, $game_window, nil, hi, nil) return false if !$name_window cw.call(0, "STATIC", "", 0x50000001, 0, 0, 320, 128, $name_window, nil, hi, nil) edit_box = cw.call(0, "EDIT", "", 0x50800081, 60, 24, 200, 24, $name_window, nil, hi, nil) ok_button = cw.call(0, "BUTTON", "OK", 0x50000001, 128, 60, 64, 26, $name_window, nil, hi, nil) sm.call(edit_box, 0xC5, char_max, 0) sf.call(edit_box) gwl.call($name_window, -4) @context = gc.call(edit_box) ss.call(@context, 1) text = "" buf = "\0" * (char_max + 1) enter = 0 loop do Graphics.update Input.update buf = "\0" * (char_max + 1) gwt.call(edit_box, buf, char_max + 1) keystate = gks.call(0x0D) & 0x8000 if keystate != 0 enter = keystate else if buf == text if enter != 0 enter = 0 break end else if text != buf text = buf enter = 0 end end end focus = gf.call() break if focus == ok_button sf.call(edit_box) if focus != edit_box end input_end return encode(text, 0, 65001) end def encode(text, f, t) m2w = Win32API.new("kernel32", "MultiByteToWideChar", "ilpipi", "i") w2m = Win32API.new("kernel32", "WideCharToMultiByte", "ilpipipp", "i") len = m2w.call(f, 0, text, -1, nil, 0); buf = "\0" * (len*2) m2w.call(f, 0, text, -1, buf, buf.size/2); len = w2m.call(t, 0, buf, -1, nil, 0, nil, nil); ret = "\0" * len w2m.call(t, 0, buf, -1, ret, ret.size, nil, nil); return ret end def input_end dw = Win32API.new("user32", "DestroyWindow", "p", "v") dw.call($name_window) $name_window = nil ss = Win32API.new("Imm32", "ImmSetOpenStatus", "pi", "v") ss.call(@context, 0) end end $game_system.input_end if $name_window