⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setonkey.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
字号:
/*  CXL - Copyright (c) 1987-1989 by Mike Smedley - All Rights Reserved  */
/*  SETONKEY.C  - attaches/detaches a key to a function  */

#include <stdlib.h>
#include "cxldef.h"
#include "cxlkey.h"

int setonkey(unsigned keycode,void (*func) (void),unsigned pass)
{
    struct _onkey_t *onkey,*prev,*next;

    /* search for a keycode that is already defined */
    onkey=_kbinfo.onkey;
    while(onkey!=NULL) {
        if( onkey->keycode == keycode ) break;
        onkey=onkey->prev;
    }

    /* check to see if a key detachment is being requested */
    if(func==NULL) {

        /* if no defined onkey was found, then error */
        if(onkey==NULL) return(2);

        /* delete record from linked list */
        prev=onkey->prev;
        next=onkey->next;
        if(prev!=NULL) prev->next=next;
        if(next!=NULL) next->prev=prev;
        if(onkey==_kbinfo.onkey) _kbinfo.onkey=prev;

        /* free memory allocated for deleted record */
        free(onkey);
    }

    else {

        /* if key was found, change func pointer */
        /* otherwise create a new onkey record */
        if(onkey!=NULL)
            onkey->func=func;
        else {

            /* allocate memory for new record */
            onkey=malloc(sizeof(struct _onkey_t));
            if(onkey==NULL) return(1);

            /* add new record to linked list */
            if(_kbinfo.onkey!=NULL) _kbinfo.onkey->next=onkey;
            onkey->prev=_kbinfo.onkey;
            onkey->next=NULL;
            _kbinfo.onkey=onkey;

            /* save info in onkey record */
            _kbinfo.onkey->keycode=keycode;
            _kbinfo.onkey->func=func;
            _kbinfo.onkey->pass=pass;
        }
    }

    /* return normally */
    return(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -