嵌入式全键盘拼音输入法分享

admin 2017-6-7 4921

最近在做拼音输入法,网上找了很多资料,但是大部分程序都是比较老的,有以下几个问题:
1.很多汉字不支持。
2.都是用在T9键盘上,全键盘输入法还没找到。
3.优化关闭可以使用,优化一旦打开就会出错。
先上图
 

大致操作流程如下:输入拼音,显示汉字,最右边大于号为翻页,循环查看。
汉字库为GB2312

部分程序如下,具体请看附件:

/*定义首字母索引表*/ 
struct PY_index *PY_index_headletter[]={PY_index_a, 
                                        PY_index_b, 
                                        PY_index_c, 
                                        PY_index_d, 
                                        PY_index_e, 
                                        PY_index_f, 
                                        PY_index_g, 
                                        PY_index_h, 
                                        PY_index_i, 
                                        PY_index_j, 
                                        PY_index_k, 
                                        PY_index_l, 
                                        PY_index_m, 
                                        PY_index_n, 
                                        PY_index_o, 
                                        PY_index_p, 
                                        PY_index_q, 
                                        PY_index_r, 
                                        PY_index_s, 
                                        PY_index_t, 
                                        PY_index_u, 
                                        PY_index_v, 
                                        PY_index_w, 
                                        PY_index_x, 
                                        PY_index_y, 
                                        PY_index_z, 
                                        PY_index_end}; 
char * py_ime(char *strInput_py_str) 
{ 
    struct PY_index *cpHZ; 
    char i,cInputStrLength; 
    cInputStrLength=strlen(strInput_py_str);    /*输入拼音串长度*/ 
    if(*strInput_py_str=='\0') return NULL;       /*如果输入空字符返回0*/ 
    for(i=0;i<cInputStrLength;i++) 
        *(strInput_py_str+i)|=0x20;             /*将字母串转为小写*/ 
    if(*strInput_py_str=='i') return NULL;        /*错误拼音输入*/ 
    if(*strInput_py_str=='u') return NULL; 
    if(*strInput_py_str=='v') return NULL; 
    cpHZ     = PY_index_headletter[strInput_py_str[0] - 'a'];      /*查首字母索引*/ 
    unsigned char count = index_number[strInput_py_str[0] - 'a'];
//    cpHZedge = PY_index_headletter[strInput_py_str[0] - 'a' + 1];  /*设置指针界限*/ 
//    printf("%x, %x\n", cpHZ, cpHZedge);
    strInput_py_str++;                           /*指向拼音串第二个字母*/ 
    while(count--)                         /*索引表不超界*/ 
    { 
        for(i=0;i<cInputStrLength;i++) 
        { 
            if(*(strInput_py_str+i)!=*((*cpHZ).PY+i)) 
                    break;    /*发现字母串不配,退出*/ 
        } 
        if(i==cInputStrLength)        /*字母串全配*/ 
        { 
            return (*cpHZ).PY_mb; 
        } 
        cpHZ++; 
    } 
    return NULL;                      /*无果而终*/ 
}

其中index_number代替了指针界线的设置,因为在实验中发现,优化后cpHZedge 居然大于cpHZ。

CSDN上一位网友提供的汉字码表。。。http://download.csdn.net/download/_flying_/634159


上传的附件:
最新回复 [0]
返回