如何控制输入法(50分)

  • 主题发起人 主题发起人 miaoyuli
  • 开始时间 开始时间
M

miaoyuli

Unregistered / Unconfirmed
GUEST, unregistred user!
比如一个窗口上放2个输入框。
当焦点定位在第一个输入框时,切换出汉字输入法输入汉字(这步操作可以通告键盘热键调出输入法)。
然后当焦点切换到第二个输入框时,则要求自动变成英文输入状态。
最后焦点切换回第一个输入框时,要求自动变成汉字输入状态。
 
修改IME属性不可以吗?
 
IMENAME 属性
 
如果你控制打开的话,可以用IMM
Delphi syntax:

type TImeMode = (imDisable, imClose, imOpen, imDontCare, imSAlpha, imAlpha, imHira, imSKata, imKata, imChinese, imSHanguel, imHanguel);

C++ syntax:

enum TImeMode { imDisable, imClose, imOpen, imDontCare, imSAlpha, imAlpha, imHira, imSKata, imKata, imChinese, imSHanguel, imHanguel };

Description

TImeMode represents the way an Input Method Editor operates to convert keyboard input typed on an Asian version of Windows. TImeMode has the following values:

Value Meaning

imDisable Shut down the IME. imDisable has no effect on Chinese, Taiwanese, or Korean IMEs.
imClose Close the IME conversion window, but leave the IME running in the background. The IME can be reactivated by a hot key combination.
imOpen Open the IME conversion window. The conversion mode is the last conversion mode used by the IME.
imDontCare Launch the IME if it is disabled. The conversion mode is the last conversion mode used by the IME.
imSAlpha Open the IME conversion window and set the conversion mode to accept single-width Roman alphabet input.

imAlpha Open the IME conversion window and set the conversion mode to accept double-width Roman alphabet input.
imHira Open the IME conversion window and set the conversion mode to double-width Hiragana. imHira is only available for Japanese IMEs.
imSKata Open the IME conversion window and set the conversion mode to single-width Katakana (Hankaku Katakana). imSKata is only available for Japanese IMEs.
imKata Open the IME conversion window and set the conversion mode to double-width Katakana (Zenkaku Katakana). imKata is only available for Japanese IMEs.

imChinese Open the IME conversion window and set the conversion mode to double-width Chinese. imChinese is only available for Chinese IMEs.
imSHanguel Open the IME conversion window and set the conversion mode to single-width Hanguel. imSHanguel is only available for Korean IMEs.
imHanguel Open the IME conversion window and set the conversion mode to double-width Hanguel. imHanguel is only available for Korean IMEs.
 
我用的D7,ImeMode我试了似乎达不到我要的效果。
第二个输入框设置成其它的模式,屏蔽不了中文输入法。
而设置成imAlpha,切换回第一个输入框又还原不了中文输入法。
 
最笨的方法:用个数组,记录每个edit 或meomo框的IME属性,切换到第一个后,只从数组里面去出输入法的IME!
 
读取系统输入法
procedure TDefIMESetFrm.FormShow(Sender: TObject);
var
J:Integer;
DBInfo: TIniFile;
iniFile: string;
begin
inherited;
for J:=0 to Screen.Imes.Count-1 do
begin
CmbIMESelect.Items.Add(Screen.Imes.Strings[j]); //获取系统中已安装的中文输入法
end;
try
IniFile := ExtractFilePath(Application.ExeName) + EOLIni;
DBInfo := TIniFile.Create(IniFile);
DefaultIMEName := DBInfo.ReadString('DefaultIME', 'DefaultIME', '');
DBInfo.Free;
finally
end;

CmbIMESelect.Text := DefaultIMEName;

end;
设置输入法,保存为文件
procedure SetIME;
var
DBInfo: TIniFile;
iniFile: string;
begin
inherited;
try
IniFile := ExtractFilePath(Application.ExeName) + EOLIni;
DBInfo := TIniFile.Create(IniFile);
DBInfo.WriteString('DefaultIME', 'DefaultIME', CmbIMESelect.Text);
DefaultIMEName := CmbIMESelect.Text;
DBInfo.Free;
finally
end;

end;
窗体创建时读取后设置
procedure TRootFrm.FormCreate(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ComponentCount - 1 do
begin
if Components is TwwDBDateTimePicker then
with TwwDBDateTimePicker(Components) do
begin
DateFormat := dfShort;
DisplayFormat := ShortDateFormat;
end
else if Components is TDateTimePicker then
with TDateTimePicker(Components) do
DateFormat := dfShort
else
if Components is TDbLinkEdit then
with TDbLinkEdit(Components) do
OnCustomEdit := CustomEdit;
if ((Components is TCustomEdit) or
(Components is TCustomComboBox)or
(Components is TCustomListBox)) and
(DefaultIMEName <> '')then
begin
if (Components is TCustomEdit) then
TDBEdit(Components).ImeName:=DefaultIMEName;
if (Components is TDBCombobox) then
TDBCombobox(Components).ImeName:=DefaultIMEName;
if (Components is TDBMemo) then
TDBMemo(Components).ImeName:=DefaultIMEName;
if (Components is TwwDBComboDlg) then
TwwDBComboDlg(Components).ImeName:=DefaultIMEName;
if (Components is TDBLinkEdit) then
TDBLinkEdit(Components).ImeName:=DefaultIMEName;
if (Components is TEdit) then
TEdit(Components).ImeName:=DefaultIMEName;
if (Components is TMemo) then
TMemo(Components).ImeName:=DefaultIMEName;
end;
end;
end;
 
我在两个输入框的ImeMode属性上设置了多种情况的组合,也达不到我问题中提出的要求效果。ImeMode到底能否控制输入法在中英之间的切换呢?
 
后退
顶部