测试换档键释放不起作用

时间:2016-01-24 07:32:49

标签: c keyboard osdev

我正在为我的操作系统开发键盘驱动程序。按某个键时,键盘驱动程序会被触发并正确转换扫描代码。现在的问题是驾驶员无法检测到正在释放的换档键。当您按下并释放shift键时,它将继续以大写字母打印字符。以下是键盘驱动程序的代码:

void keyboard()
{
    static char scancode[58] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
        0, 0, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0, 0, 'a', 's', 'd',
        'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n',
        'm', ',', '.',
        '/', 0, 0, 0, ' '
    };
    static char shift_scancode[58] = { 0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
        0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0, 'A', 'S', 'D', 'F',
        'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>',
        '?', 0, 0, 0, ' '
    };
    unsigned char status;       // detects status of buffer
    char keycode;               //scancode
    char release;
    status = inportb(0x64);     // get status of port
    if (status & 0x01) {        // check if bit 0 is set
        keycode = inportb(0x60);        // get key pressed
        if (keycode == 42 || keycode == 54) {
            *shift = 1;         // shift is pressed.*shift is global and volatile
        }
        if (keycode == 0xaa || keycode == 0xb6) {       // part not working
            println("Shift release detected");
            *shift = 0;
        }
        if (keycode <= 57 && scancode[keycode] != 0 && *shift == 0) {   // check if keycode is a normal key and shift is released
            *buffer = scancode[keycode];
            printc(scancode[keycode]);
            release = inportb(0x60);
        }
        if (keycode <= 57 && scancode[keycode] != 0 && *shift == 1) {
            *buffer = shift_scancode[keycode];
            printc(shift_scancode[keycode]);
            release = inportb(0x60);
        } else {
            *buffer = keycode;  //used to check scancode
        }
    }
    outportb(0x20, 0x20);       //eoi
}

我知道问题出现在那个根本没有被调用的问题上,因为我做了内存转储。它显示shift键已释放且缓冲区为= 0xaa*shift指针仍设置为1而不是0.如何解决此问题?有什么建议吗?

0 个答案:

没有答案