回 帖 发 新 帖 刷新版面

主题:[讨论]能人异士快杀进来!(关于中文输入)

请问:有谁有办法在软件中使用中文输入,不是指编写时所输入的中文,是指在软件运行过程能输入中文。举一个例子,用pascal写的笔记本怎样能输入中文。
-----------------------------------------------------------------------------------
有谁有什么好提议吗?

回复列表 (共18个回复)

11 楼

比赛时都用FreePascal

12 楼

sqace键在哪?

13 楼

是space,空格键

14 楼

基本上弄明白了楼主的意思:自己写个输入法。。
这里又个C言写的。看看你能不能用上,我也是参考了这个才写了个QB的输入法

#include<stdio.h>
#include<graphics.h>
#include<string.h>
#include<dos.h>

#define TIMER       0x1c                   /* 时钟中断号 */

#define KEY_ESC     0x011b

/* 状态参数,对应于 status 变量 */
#define NOPY        0                      /* 汉字输入状态下,没有拼音字符 */
#define INPUTPY     1                      /* 汉字输入状态下,正在输入拼音字符 */
#define CHOOSE      2                      /* 汉字输入状态下,结束输入拼音,开始选择汉字 */
#define ENGLISH     3                      /* 英文输入状态 */


typedef struct
{
 char pinyin[7];        /* Dic.md表中,拼音字母占七个字节 */
 unsigned position;     /* 该音的第一个汉字偏移位置( 4320D+2*position ) */
 unsigned char num;     /*  */
}PINYIN;

int Counter;                               /* 计数变量 */

void interrupt (*oldhandler)(void);

void interrupt newhandler(void)
{
 Counter++;
 oldhandler();
}

void begin(void interrupt (*IntProc)(void))
{
 oldhandler=getvect(TIMER);
 disable();
 setvect(TIMER,IntProc);
 enable();
}

void shut(void)
{
 disable();
 setvect(TIMER,oldhandler);
 enable();
}

void hanzi(int x,int y,char *s,int colour)
{
 FILE *fp;
 char buffer[32];
 register i,j,k;
 unsigned char qh,wh;
 unsigned long location;
 if((fp=fopen("hzk16","rb"))==NULL)
 {
  printf("Can't open hzk16!");
  getch();
  exit(0);
 }
 while(*s)
 {
  qh=*s-0xa0;
  wh=*(s+1)-0xa0;
  location=(94*(qh-1)+(wh-1))*32L;
  fseek(fp,location,SEEK_SET);
  fread(buffer,32,1,fp);
  for(i=0;i<16;i++)
   for(j=0;j<2;j++)
    for(k=0;k<8;k++)
     if(((buffer[i*2+j]>>(7-k))&0x1)!=NULL)
      putpixel(x+8*j+k,y+i,colour);
  s+=2;
  x+=16;
 }
 fclose(fp);
}

void hanzi1(int x,int y,char *s,int colour)
{
 FILE *fp;
 char buffer[32];
 register i,j,k;
 unsigned char qh,wh;
 unsigned long location;
 if((fp=fopen("hzk16","rb"))==NULL)
  {
   printf("Can't open hzk16!");
   getch();
  }
 qh=*s-0xa0;
 wh=*(s+1)-0xa0;
 location=(94*(qh-1)+(wh-1))*32L;
 fseek(fp,location,SEEK_SET);
 fread(buffer,32,1,fp);
 for(i=0;i<16;i++)
  for(j=0;j<2;j++)
   for(k=0;k<8;k++)
    if(((buffer[i*2+j]>>(7-k))&0x1)!=NULL)
     putpixel(x+8*j+k,y+i,colour);
 fclose(fp);
}

void myouttext(int x,int y,char *s,char colour)
{
 register int i,j,k;
 int loc=0;
 FILE *fp;
 char buffer[16];
 fp=fopen("asc16","rb");
 while(*s)
 {
  fseek(fp,(*s)*16,0);
  fread(buffer,1,16,fp);
  for(i=0;i<16;i++)
   for(j=0;j<8;j++)
   {
    if(((buffer[i]>>(7-j))&0x1)!=NULL)
    putpixel(j+x+loc,i+y,colour);
   }
  s++;
  loc+=8;
 }
 fclose(fp);
}

15 楼

void puts16(int x,int y,char *s,unsigned char colour)
{
 register int i,j,k;
 FILE *fpa,*fph;
 char buffera[16],bufferh[32];
 unsigned char qh,wh;
 unsigned long location;

 fpa=fopen("asc16","rb");
 fph=fopen("hzk16","rb");
 while(*s)
  {
   if(*s>0)
    {
     fseek(fpa,(*s)*16,0);
     fread(buffera,1,16,fpa);
     for(i=0;i<16;i++)
      for(j=0;j<8;j++)
       {
        if(((buffera[i]>>(7-j))&0x1)!=NULL)
        putpixel(j+x,i+y,colour);
       }
     s++;
     x+=8;
    }
   else
    {
     qh=*s-0xa0;
     wh=*(s+1)-0xa0;
     location=(94*(qh-1)+(wh-1))*32L;
     fseek(fph,location,SEEK_SET);
     fread(bufferh,32,1,fph);
     for(i=0;i<16;i++)
      for(j=0;j<2;j++)
       for(k=0;k<8;k++)
        if(((bufferh[i*2+j]>>(7-k))&0x1)!=NULL)
         putpixel(x+8*j+k,y+i,colour);
     s+=2;
     x+=16;
    }
  }
 fclose(fpa);
 fclose(fph);
}

void hanzi10(char *s,int remainder)
{
 FILE *fp;
 int num;
 int x=240,y=462;
 char buffer[32];
 char figure[10][2]={"1","2","3","4","5","6","7","8","9","0"};
 register i,j,k;
 unsigned char qh,wh;
 unsigned long location;
 if((fp=fopen("hzk16","rb"))==NULL)
 {
  printf("Can't open hzk16!");
  getch();
  exit(0);
 }
 setfillstyle(1,LIGHTGRAY);
 bar(240,460,639,479);
 for(num=0;num<remainder;num++)
  {
   myouttext(x,y,figure[num],BLACK);
   x+=8;
   qh=*s-0xa0;
   wh=*(s+1)-0xa0;
   location=(94*(qh-1)+(wh-1))*32L;
   fseek(fp,location,SEEK_SET);
   fread(buffer,32,1,fp);
   for(i=0;i<16;i++)
    for(j=0;j<2;j++)
     for(k=0;k<8;k++)
      if(((buffer[i*2+j]>>(7-k))&0x1)!=NULL)
       putpixel(x+8*j+k,y+i,BLACK);
   s+=2;
   x+=24;
  }

 fclose(fp);
}

void input(int cursorx,int cursory,char *s,unsigned char colour)
{
 PINYIN index;
 int status=NOPY;
 int danyin=0,shuangyin=0;
 int i=0,j=0,k=0;
 int x=128,y=462;
 int pages,page,remainder,location;
 char qjsign[80],bjsign[40];         /* 全角及半角符号数组 */
 char c=0;                           /* 获取输入键值,以备处理 */
 char eng[10];                       /* 拼音字符串数组 */
 char allhanzi[256][2];              /* 相同拼音的汉字数组 */
 char temp[2]={'\0','\0'};
 FILE *fp;
 fp=fopen("dic.mb","rb");
/* 读取全角及半角符号数组 */
 fseek(fp,420*10,SEEK_SET);
 fread(qjsign,2,40,fp);
 fread(bjsign,1,40,fp);
/* 画屏幕底部状态条 */
 setfillstyle(1,LIGHTGRAY);
 bar(0,460,639,479);
 hanzi(32,462,"拼音输入",BLUE);
 begin(newhandler);

 do
 {
  if(bioskey(1))
   {
    c=bioskey(0);

/* 以下是对Ctrl+Space的处理 */
    if(c==' ')
     {
      if(bioskey(2)==0x24)
       {
        if(status!=ENGLISH)
         {
          status=ENGLISH;
          i=0;
          x=128;
          setfillstyle(1,LIGHTGRAY);
          bar(0,460,639,479);
          hanzi(32,462,"英文输入",BLUE);
         }
        else
         {
          status=NOPY;
          setfillstyle(1,LIGHTGRAY);
          bar(0,460,639,479);
          hanzi(32,462,"拼音输入",BLUE);
         }
        c=0;
       }
     }

16 楼

/* 以下是对退格键BackSpace的处理 */
    if(c=='\b')
     {
      if(status==INPUTPY)
       {
        if(i>0)
         {
          x-=8;
          i--;
          if(i==0)status=NOPY;
          setfillstyle(1,LIGHTGRAY);
          bar(x,y,x+7,y+16);
         }
        c=0;
       }

      if(status==NOPY||status==ENGLISH)
       {
        setcolor(BLACK);
        setfillstyle(1,BLACK);

        if(k>0)
         {
          rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
          if(s[--k]>0)
           {
            cursorx-=8;
            bar(cursorx,cursory,cursorx+15,cursory+16);
           }
          else
           {
            cursorx-=16;
            k--;
            bar(cursorx,cursory,cursorx+15,cursory+16);
           }
         }
        c=0;
       }
     }

/* 以下是对拼音的处理 */
    if(c>='a'&&c<='z')
     {
      if(status==NOPY)
       status=INPUTPY;
      if(i<6&&(status==NOPY||status==INPUTPY))
       {
        eng[i++]=c;
        temp[0]=c;
        myouttext(x,y,temp,BLACK);
        x+=8;
        c=0;
       }
     }

/* 以下是对英文输入的处理 */
    if(status==ENGLISH)
     {
      if(c>=' '&&c<='~')
       {
        setcolor(BLACK);
        rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
        s[k++]=c;
        temp[0]=c;
        myouttext(cursorx,cursory,temp,colour);
        cursorx+=8;
        c=0;
       }
     }

/* 以下是对全角符号的处理 */
    if(status==NOPY)
     {
      if((c>=' '&&c<='/'||c>=':'&&c<='@'||c>='['&&c<='`'||c>='{'&&c<='~')&&c!='\''&&c!='\"')
       {
        for(j=0;j<40;j++)
         if(bjsign[j]==c)
          break;
        hanzi1(cursorx,cursory,qjsign+2*j,colour);
        s[k++]=qjsign[2*j];
        s[k++]=qjsign[2*j+1];
        setcolor(BLACK);
        rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
        cursorx+=16;
        c=0;
       }
      /* 以下是对全角符号中引号的处理 */
      if(c=='\'')
       {
        for(j=0;j<40;j++)
         if(bjsign[j]==c)
          break;
        if(danyin)
         j++;
        danyin=(danyin+1)%2;
        hanzi1(cursorx,cursory,qjsign+2*j,colour);
        s[k++]=qjsign[2*j];
        s[k++]=qjsign[2*j+1];
        setcolor(BLACK);
        rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
        cursorx+=16;
        c=0;
       }
      if(c=='\"')
       {
        for(j=0;j<40;j++)
         if(bjsign[j]==c)
          break;
        if(shuangyin)
         j++;
        shuangyin=(shuangyin+1)%2;
        hanzi1(cursorx,cursory,qjsign+2*j,colour);
        s[k++]=qjsign[2*j];
        s[k++]=qjsign[2*j+1];
        setcolor(BLACK);
        rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
        cursorx+=16;
        c=0;
       }
     }

/* 以下是拼音输入状态下,对ESC键的处理 */
    if(c==27)
     {
      if(status==INPUTPY||status==CHOOSE)
      status=NOPY;
      i=0;
      x=128;
      setfillstyle(1,LIGHTGRAY);
      bar(128,460,639,479);
     }

17 楼

/* 以下是输入空格和回车,结束拼音输入的处理 */
    if(status==INPUTPY)
     {
      if(c==' '||c=='\r')
       {
        status=CHOOSE;
        eng[i]='\0';
        for(j=0;j<416;j++)
         {
          fseek(fp,j*10,SEEK_SET);
          fread(index.pinyin,1,7,fp);
          if(!strcmp(eng,index.pinyin))
           break;
         }
        if(j==416)       /* 如果不存在此拼音,则重新输入 */
         {
          status=NOPY;
          i=0;
          x=128;
          setfillstyle(1,LIGHTGRAY);
          bar(128,460,180,479);
         }
        else
         {
          fseek(fp,j*10,SEEK_SET);
          fread(&index,sizeof(PINYIN),1,fp);
          fseek(fp,4320+2*index.position,SEEK_SET);/* 指针移到相应汉字内码偏移位置,首地址偏移:4320D=10e0H */ 
          fread(allhanzi,2,index.num,fp);
          pages=index.num/10;
          remainder=index.num-pages*10;
          if(remainder==0)
           {
            pages--;
            remainder=10;
           }
          page=0;
          if(pages==0)
           hanzi10(allhanzi[0],remainder);
          else
           hanzi10(allhanzi[0],10);
         }
        c=0;
       }
     }

/* 以下是对汉字选择的处理 */
    if(status==CHOOSE)
     {
      if(c=='='||c=='.')
       {
        if(page<pages)
         {
          page++;
          if(page==pages)
           hanzi10(allhanzi[10*page],remainder);
          else
           hanzi10(allhanzi[10*page],10);
         }
        c=0;
       }

      if(c=='-'||c==',')
       {
        if(page>0)
         {
          page--;
          hanzi10(allhanzi[10*page],10);
         }
        c=0;
       }

      if(c>='0'&&c<='9'||c==' '||c=='\r')
       {
        if(c=='0')
         location=9;
        else
         location=c-49;
        if(c==' '||c=='\r')
         location=0;

        if(page==pages)
         {
          if(location<remainder)
           {
            status=NOPY;
            hanzi1(cursorx,cursory,allhanzi[page*10+location],colour);
            s[k++]=allhanzi[page*10+location][0];
            s[k++]=allhanzi[page*10+location][1];
            setcolor(BLACK);
            rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
            cursorx+=16;
            i=0;
            x=128;
            setfillstyle(1,LIGHTGRAY);
            bar(240,460,639,479);
            bar(128,460,180,479);
           }
         }
        else
         {
          status=NOPY;
          hanzi1(cursorx,cursory,allhanzi[page*10+location],colour);
          s[k++]=allhanzi[page*10+location][0];
          s[k++]=allhanzi[page*10+location][1];
          setcolor(BLACK);
          rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
          cursorx+=16;
          i=0;
          x=128;
          setfillstyle(1,LIGHTGRAY);
          bar(240,460,639,479);
          bar(128,460,180,479);
         }
        c=0;
       }
     }

/* 按键处理完毕 */
   }

/* 光标处理 */
  if(Counter>2)
   {
    Counter=0;
    j++;
    j%=2;
    if(j)
     {
      setcolor(BLACK);
      rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
     }
    else
     {
      setcolor(colour);
      rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
     }
   }
 }while(c!='\r');

 s[k]='\0';
 setcolor(BLACK);
 rectangle(cursorx,cursory+16,cursorx+6,cursory+17);
 shut();
 fclose(fp);
}


main()
{
 char s[256];
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"");

 input(150,200,s,GREEN);
 puts16(20,20,s,LIGHTRED);

 getch();
 closegraph();
}

18 楼

[quote]基本上弄明白了楼主的意思:自己写个输入法。。
这里又个C言写的。看看你能不能用上,我也是参考了这个才写了个QB的输入法


[/quote]

[size=4][color=FF0000]严重的谢谢!!![/color][/size]

我来回复

您尚未登录,请登录后再回复。点此登录或注册