我不是高手,也不是笨蛋,可是这个问题我不会(Hook问题)(200分)

  • 主题发起人 主题发起人 Kule
  • 开始时间 开始时间
K

Kule

Unregistered / Unconfirmed
GUEST, unregistred user!
使用日志hook监视键盘输入时,如何判断当前输入的是中文还是英文?
如果是中文怎么获得输入文字,高手赐教!
 
判断输入值是否大于等于>$a0
在GB2312的6763个汉字中,每一个汉字由两个>$a0的字符组成。
在GBK大字符集汉字中, 汉字的第一个字符大于等于$a0,第二个则不一定。
判断到了,自然也就得到了。
 
老问题了,htw基本说出概要了。
 
怎么得到汉字,是否可以说得清楚一点?谢谢
 
1.GBK编码,兼容GB2312,简、繁体字融于一库,其第一字节的值在 16 进制的
81~FE (129~254) 之间,第二字节在 40~FE,(64~254)除去7F(127)一线。
2.相关例程供参考:
sContext := Memosou.Text;
I := 1;
while (I <= length(sContext)) do begin
if ((sContext >= #129) and (sContext <= #254)) then begin //判断是否是GBK汉字
if (((sContext[I + 1] >= #64) and (sContext[I + 1] < #127))
or ((sContext[I + 1] > #127) and (sContext[I + 1] <= #254))) then
showmessage('汉字');
end;
end;
 

procedure TForm1.Button1Click(Sender: TObject);
var
character,i,characterenglish,characterchinese:integer;
str:string;
begin
i:=1;
character:=0;
str:=memo1.Lines.Text;
if length(str)>0 then
while not(i>length(str)) do
begin
if (ord(str)=32) then
i:=i+1
else if(ord(str)=13) then
i:=i+2
else
begin
if(ord(str)>=129) and(ord(str)<=254) and (ord(str[i+1])>=64) and (ord(str[i+1])<=254) then
begin
i:=i+2;
character:=character+1;
characterchinese:=characterchinese+1;
end
else
begin
i:=i+1;
character:=character+1;
characterenglish:=characterenglish+1;
end;
end;
end;
label1.caption:='总共字符'+inttostr(character);
label4.Caption:='中文字符'+inttostr(characterchinese);
label6.Caption:='英文字符'inttostr(characterenglish);
end;
 
接受答案了.
 

Similar threads

D
回复
0
查看
851
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部