Input Method Editor for JPN CHN

Share your advanced PureBasic knowledge/code with the community.
User avatar
oryaaaaa
Addict
Addict
Posts: 825
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Input Method Editor for JPN CHN

Post 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
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post 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.
Post Reply