📄 pc_keyb.c
字号:
if (((key_shifts & KB_NUMLOCK_FLAG) != 0) == ((key_shifts & KB_SHIFT_FLAG) != 0)) { scancode = numlock_table[scancode - KEY_0_PAD]; } table = standard_key_ascii_table; } else if (key_shifts & KB_CTRL_FLAG) { table = standard_key_control_table; } else if (key_shifts & KB_SHIFT_FLAG) { if (key_shifts & KB_CAPSLOCK_FLAG) { if (standard_key_ascii_table[scancode] == standard_key_capslock_table[scancode]) { table = standard_key_shift_table; } else { table = standard_key_ascii_table; } } else { table = standard_key_shift_table; } } else if (key_shifts & KB_CAPSLOCK_FLAG) { table = standard_key_capslock_table; } else { table = standard_key_ascii_table; } key_buffer.key[key_buffer.end++] = (scancode << 16) | table[scancode]; if (key_buffer.end >= KEY_BUFFER_SIZE) key_buffer.end = 0; if (key_buffer.end == key_buffer.start) { key_buffer.start++; if (key_buffer.start >= KEY_BUFFER_SIZE) key_buffer.start = 0; }} ENDOFUNC(inject_key)static voidhandle_code (int scancode, int keycode){ in_a_terrupt++; if (keycode == 0) { /* pause */ inject_key(scancode); pc_key[KEY_PAUSE] ^= TRUE; } else if (scancode) { int flag; if (scancode >= KEY_MODIFIERS) { flag = modifier_table[scancode - KEY_MODIFIERS]; } else { flag = 0; } if ((char)keycode < 0) { /* release */ pc_key[scancode] = FALSE; if (flag & KB_MODIFIERS) { key_shifts &= ~flag; } } else { /* keypress */ pc_key[scancode] = TRUE; if (flag & KB_MODIFIERS) { key_shifts |= flag; } if (flag & KB_LED_FLAGS) { key_shifts ^= flag; update_leds(key_shifts); } if (scancode < KEY_MODIFIERS) { inject_key(scancode); } } } in_a_terrupt--;} ENDOFUNC(handle_code)static intkeyboard (){ unsigned char temp, scancode; temp = inportb(0x60); if (temp <= 0xe1) { if (key_pause_loop) { if (!--key_pause_loop) handle_code(KEY_PAUSE, 0); } else switch (temp) { case 0xe0: key_enhanced = TRUE; break; case 0xe1: key_pause_loop = 5; break; default: if (key_enhanced) { key_enhanced = FALSE; scancode = hw_to_mycode_ex[temp & 0x7f]; } else { scancode = hw_to_mycode[temp & 0x7f]; } handle_code(scancode, temp); } } if (((temp==0x4F)||(temp==0x53))&&(key_shifts&KB_CTRL_FLAG)&&(key_shifts&KB_ALT_FLAG)) { /* Hack alert: * only SIGINT (but not Ctrl-Break) * calls the destructors and will safely clean up */ __asm("\n\ movb $0x79, %%al \n\ call ___djgpp_hw_exception \n\ ":::"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); } __asm("\n\ inb $0x61, %%al \n\ movb %%al, %%ah \n\ orb $0x80, %%al \n\ outb %%al, $0x61 \n\ xchgb %%al, %%ah \n\ outb %%al, $0x61 \n\ movb $0x20, %%al \n\ outb %%al, $0x20 \n\ ":::"%eax"); return 0;} ENDOFUNC(keyboard)intpc_keypressed (void){ return (key_buffer.start!=key_buffer.end);}intpc_readkey (void){ if (keyboard_installed) { int key; while (key_buffer.start == key_buffer.end) { __dpmi_yield(); } DISABLE(); key = key_buffer.key[key_buffer.start++]; if (key_buffer.start >= KEY_BUFFER_SIZE) key_buffer.start = 0; ENABLE(); return key; } else { return 0; }}intpc_keydown (int code){ return pc_key[code];}intpc_keyshifts (void){ return key_shifts;}voidpc_remove_keyb (void){ if (keyboard_installed) { int s1, s2, s3; keyboard_installed = FALSE; pc_clexit(pc_remove_keyb); DISABLE(); _farsetsel(__djgpp_dos_sel); _farnspokew(0x41c, _farnspeekw(0x41a)); s1 = _farnspeekb(0x417) & 0x80; s2 = _farnspeekb(0x418) & 0xFC; s3 = _farnspeekb(0x496) & 0xF3; if (pc_key[KEY_RSHIFT]) { s1 |= 1; } if (pc_key[KEY_LSHIFT]) { s1 |= 2; } if (pc_key[KEY_LCONTROL]) { s2 |= 1; s1 |= 4; } if (pc_key[KEY_ALT]) { s1 |= 8; s2 |= 2; } if (pc_key[KEY_RCONTROL]) { s1 |= 4; s3 |= 4; } if (pc_key[KEY_ALTGR]) { s1 |= 8; s3 |= 8; } if (key_shifts & KB_SCROLOCK_FLAG) s1 |= 16; if (key_shifts & KB_NUMLOCK_FLAG) s1 |= 32; if (key_shifts & KB_CAPSLOCK_FLAG) s1 |= 64; _farnspokeb(0x417, s1); _farnspokeb(0x418, s2); _farnspokeb(0x496, s3); update_leds(key_shifts); ENABLE(); pc_remove_irq(KEYB_IRQ); }}intpc_install_keyb (void){ if (keyboard_installed || pc_install_irq(KEYB_IRQ, keyboard)) { return -1; } else { int s1, s2, s3; LOCKDATA(key_buffer); LOCKDATA(key_enhanced); LOCKDATA(key_pause_loop); LOCKDATA(key_shifts); LOCKDATA(leds_ok); LOCKDATA(in_a_terrupt); LOCKDATA(pc_key); LOCKDATA(modifier_table); LOCKDATA(hw_to_mycode); LOCKDATA(hw_to_mycode_ex); LOCKDATA(standard_key_ascii_table); LOCKDATA(standard_key_capslock_table); LOCKDATA(standard_key_shift_table); LOCKDATA(standard_key_control_table); LOCKDATA(numlock_table); LOCKFUNC(update_leds); LOCKFUNC(inject_key); LOCKFUNC(handle_code); LOCKFUNC(keyboard); DISABLE(); _farsetsel(__djgpp_dos_sel); _farnspokew(0x41c, _farnspeekw(0x41a)); key_shifts = 0; s1 = _farnspeekb(0x417); s2 = _farnspeekb(0x418); s3 = _farnspeekb(0x496); if (s1 & 1) { key_shifts |= KB_SHIFT_FLAG; pc_key[KEY_RSHIFT] = TRUE; } if (s1 & 2) { key_shifts |= KB_SHIFT_FLAG; pc_key[KEY_LSHIFT] = TRUE; } if (s2 & 1) { key_shifts |= KB_CTRL_FLAG; pc_key[KEY_LCONTROL] = TRUE; } if (s2 & 2) { key_shifts |= KB_ALT_FLAG; pc_key[KEY_ALT] = TRUE; } if (s3 & 4) { key_shifts |= KB_CTRL_FLAG; pc_key[KEY_RCONTROL] = TRUE; } if (s3 & 8) { key_shifts |= KB_ALT_FLAG; pc_key[KEY_ALTGR] = TRUE; } if (s1 & 16) key_shifts |= KB_SCROLOCK_FLAG; if (s1 & 32) key_shifts |= KB_NUMLOCK_FLAG; if (s1 & 64) key_shifts |= KB_CAPSLOCK_FLAG; update_leds(key_shifts); key_enhanced = key_pause_loop = 0; key_buffer.start = key_buffer.end = 0; ENABLE(); pc_atexit(pc_remove_keyb); keyboard_installed = TRUE; return 0; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -