Page 1 of 1

Input Method Editor for JPN CHN

Posted: Fri Jun 30, 2006 10:29 pm
by oryaaaaa
Code updated For 5.20+

Code: Select all

    ;-
    ;-  IME On/Off
    ;-
    ;    Author:: akira takama
    ; http://forum.oryaaaaa.com/viewtopic.php?t=126
    ;
    ; fep = Front End Processor
    ; ime = Input Method Editor

    #IME_Hiragana = $8 | $1 ; Hiragana
    #IME_Katakana = $8 | $3 ; 2byte katakana
    #IME_Katakana_Half = $3 ;1byte katakana
    #IME_ENGnumber = $8 ;2byte english&number
    #IME_ENGnumber_Half = $0  ;1 byte english&number

    Procedure fepon(WinID.l,inputmode.l)
      hwnd.l
      CStatus.l
      SStatus.l
      Ret.l
      hwnd = ImmGetContext_(WindowID(WinID))
      If hwnd <> 0
        If ImmGetOpenStatus_(hwnd) <> -1  ;  dont launch IME
          Ret = ImmSetOpenStatus_(hwnd, -1)      ; open IME
          CStatus = inputmode                   ; initial input mode
          ; initial convert mode
          SStatus = $8                          ; #IME_SMODE_PHRASEPREDICT
          ; Set Initial mode
          Ret = ImmSetConversionStatus_(hwnd, CStatus, SStatus)
          Ret = ImmSetOpenStatus_(hwnd, #False)   ; Close IME
        EndIf
        ; Release input context
        Ret = ImmReleaseContext_(WindowID(WinID), hwnd)
      EndIf
      wh = ImmGetContext_(WindowID(WinID))
      ImmSetOpenStatus_(wh, #True)
    EndProcedure

    Procedure fepoff(WinID.l)
      wh = ImmGetContext_(WindowID(WinID))
      ImmSetOpenStatus_(wh, #False)
    EndProcedure

    OpenWindow(0,0,0,100,100, "IME TEST",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

    ButtonGadget  (1, 10, 10,90, 30, "IME ON")
    EditorGadget(2, 10, 45, 90, 45)

    Repeat
      EventID = WaitWindowEvent()
      If EventID = #PB_Event_Gadget And EventGadget() = 1
        SetActiveGadget(2)
        fepon(0, #IME_ENGnumber_Half)
      EndIf
    Until EventID = #PB_Event_CloseWindow
    End

Posted: Sat Jul 01, 2006 9:21 am
by mskuma
Thanks oryaaaaa for posting this - it is interesting & useful (for Japanese input on forms). I've noticed that it only works if your IME is already set to Japanese (which it would be for 99% of users in Japan). It doesn't do anything if the IME is set to English (same for any other language presumably). So in this case, it would be necessary to update the code to make sure the IME is already set to Japanese (or do the switch) first for this code to be effective.