Apr 28

CTRL的ASCII - delphi的程序 不指定

adminleon , 22:59 , delphi , 评论(0) , 引用(0) , 阅读(28) , Via 本站原创 | |

由于帮朋友编程序,程式是用delphi编写,编的是com程序,用的控件是spcomm,要输入Ctrl + Z 键,但总是得不到预想的效果,

我原先这样用的:
var
ss:string

begin
// #17 是ctrl键的ascii码,#90是Z的ascii码,#13是回车的ascii码
ss:=#17#90#13
Comm1.WriteCommData(Pchar(ss),Length(ss));

end;

但总是不对,后来在网上查到CTRL+ Z 是用组合键的ASCII码的,不是#17#90#13了事,应该这样,

ctrl + a 应该是 #1
  .
  .
  .
ctrl + z 应该是 #25
ctrl + z 应该是 #26

经这样实践之后就ok了。

下边是个输出ctrl + a~z的函数

CtrlStr(a) 等于#1 , 写得有点复杂.


function  CtrlStr(fstr:string):string;
var
vstr:string;
begin
fstr:=uppercase(fstr);
if fstr='A' then
  vstr:=#1
else if fstr='B' then
  vstr:=#2
else if fstr='C' then
  vstr:=#3
else if fstr='D' then
  vstr:=#4
else if fstr='E' then
  vstr:=#5
else if fstr='F' then
  vstr:=#6
else if fstr='G' then
  vstr:=#7
else if fstr='H' then
  vstr:=#8
else if fstr='I' then
  vstr:=#9
else if fstr='J' then
  vstr:=#10
else if fstr='K' then
  vstr:=#11
else if fstr='L' then
  vstr:=#12
else if fstr='M' then
  vstr:=#13
else if fstr='N' then
  vstr:=#14
else if fstr='O' then
  vstr:=#15
else if fstr='P' then
  vstr:=#16
else if fstr='Q' then
  vstr:=#17
else if fstr='R' then
  vstr:=#18
else if fstr='S' then
  vstr:=#19
else if fstr='T' then
  vstr:=#20
else if fstr='U' then
  vstr:=#21
else if fstr='v' then
  vstr:=#22
else if fstr='W' then
  vstr:=#23
else if fstr='X' then
  vstr:=#24
else if fstr='Y' then
  vstr:=#25
else if fstr='Z' then
  vstr:=#26
else
  vstr:='';

result:=vstr;


end;
Tags: , ,
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]