📄 keyboard.c
字号:
break; } set_console(vt_con_data + i);}static void incr_console (void){ int i; int fgnum = vtdata.fgconsole->num - 1; for (i = fgnum + 1; i != fgnum; i++) { if (i == MAX_NR_CONSOLES) i = 0; if (vt_allocated (vt_con_data + i)) break; } set_console(vt_con_data + i);}static void send_intr (void){ if (!tty) return; tty_insert_flip_char (tty, 0, TTY_BREAK); tty_schedule_flip (tty);}static void scroll_forw (void){ scrollfront(0);}static void scroll_back (void){ scrollback(0);}static void boot_it (void){ ctrl_alt_del();}static void compose (void){ dead_key_next = 1;}int spawnpid, spawnsig;static void spawn_console (void){ if (spawnpid) if (kill_proc (spawnpid, spawnsig, 1)) spawnpid = 0;}static void SAK (void){ do_SAK(tty);#if 0 /* * Need to fix SAK handling to fix up RAW/MEDIUM_RAW and * vt_cons modes before we can enable RAW/MEDIUM_RAW SAK * handling. * * We should do this some day --- the whole point of a secure * attention key is that it should be guaranteed to always * work. */ vt_reset (vtdata.fgconsole); do_unblank_screen (); /* not in interrupt routine? */#endif}static void do_ignore (unsigned char value, char up_flag){}static void do_null (void){ compute_shiftstate ();}static void do_spec (unsigned char value,char up_flag){ if (up_flag) return; if (value >= SIZE(spec_fn_table)) return; spec_fn_table[value] ();}static void do_lowercase (unsigned char value, char up_flag){ printk(KERN_ERR "keyboard.c: do_lowercase was called - impossible\n");}static void do_self(unsigned char value, char up_flag){ if (up_flag) return; /* no action, if this is a key release */ if (diacr) value = handle_diacr (value); if (dead_key_next) { dead_key_next = 0; diacr = value; return; } put_queue (value);}#define A_GRAVE '`'#define A_ACUTE '\''#define A_CFLEX '^'#define A_TILDE '~'#define A_DIAER '"'#define A_CEDIL ','static unsigned char ret_diacr[] = {A_GRAVE, A_ACUTE, A_CFLEX, A_TILDE, A_DIAER, A_CEDIL };/* If a dead key pressed twice, output a character corresponding to it, *//* otherwise just remember the dead key. */static void do_dead(unsigned char value, char up_flag){ if (up_flag) return; value = ret_diacr[value]; if (diacr == value) { /* pressed twice */ diacr = 0; put_queue (value); return; } diacr = value;}/* If space is pressed, return the character corresponding the pending *//* dead key, otherwise try to combine the two. */static unsigned char handle_diacr(unsigned char ch){ int d = diacr; int i; diacr = 0; if (ch == ' ') return d; for (i = 0; i < accent_table_size; i++) { if (accent_table[i].diacr == d && accent_table[i].base == ch) return accent_table[i].result; } put_queue (d); return ch;}static void do_cons(unsigned char value, char up_flag){ if (up_flag) return; set_console(vt_con_data + value);}static void do_fn(unsigned char value, char up_flag){ if (up_flag) return; if (value < SIZE(func_table)) { if (func_table[value]) puts_queue (func_table[value]); } else printk (KERN_ERR "do_fn called with value=%d\n",value);}static void do_pad(unsigned char value, char up_flag){ static const char *pad_chars = "0123456789+-*/\015,.?#"; static const char *app_map = "pqrstuvwxylmRQMnn?S"; if (up_flag) return; /* no action, if this is a key release */ /* kludge... shift forces cursor/number keys */ if (vc_kbd_mode (kbd, VC_APPLIC) && !k_down[KG_SHIFT]) { applkey (app_map[value], 1); return; } if (!vc_kbd_led (kbd,VC_NUMLOCK)) switch (value) { case KVAL(K_PCOMMA): case KVAL(K_PDOT): do_fn (KVAL(K_REMOVE), 0); return; case KVAL(K_P0): do_fn (KVAL(K_INSERT), 0); return; case KVAL(K_P1): do_fn (KVAL(K_SELECT), 0); return; case KVAL(K_P2): do_cur(KVAL(K_DOWN), 0); return; case KVAL(K_P3): do_fn (KVAL(K_PGDN), 0); return; case KVAL(K_P4): do_cur(KVAL(K_LEFT), 0); return; case KVAL(K_P6): do_cur(KVAL(K_RIGHT), 0); return; case KVAL(K_P7): do_fn (KVAL(K_FIND), 0); return; case KVAL(K_P8): do_cur(KVAL(K_UP), 0); return; case KVAL(K_P9): do_fn (KVAL(K_PGUP), 0); return; case KVAL(K_P5): applkey('G',vc_kbd_mode(kbd, VC_APPLIC)); return; } put_queue (pad_chars[value]); if (value == KVAL(K_PENTER) && vc_kbd_mode (kbd, VC_CRLF)) put_queue (10);}static void do_cur(unsigned char value, char up_flag){ static const char *cur_chars = "BDCA"; if (up_flag) return; applkey (cur_chars[value], vc_kbd_mode(kbd, VC_CKMODE));}static void do_shift(unsigned char value, char up_flag){ int old_state = shift_state; if (rep) return; /* Mimic typewriter: a CapsShift key acts like Shift but undoes CapsLock */ if (value == KVAL(K_CAPSSHIFT)) { value = KVAL(K_SHIFT); if (!up_flag) clr_vc_kbd_led (kbd, VC_CAPSLOCK); } if(up_flag) { /* handle the case that two shift or control keys are depressed simultaneously */ if(k_down[value]) k_down[value]--; } else k_down[value]++; if(k_down[value]) shift_state |= (1 << value); else shift_state &= ~ (1 << value); /* kludge */ if(up_flag && shift_state != old_state && npadch != -1) { if(kbd->kbdmode == VC_UNICODE) to_utf8(npadch & 0xffff); else put_queue(npadch & 0xff); npadch = -1; }}/* * Called after returning from RAW mode or when changing consoles - * recompute k_down[] and shift_state from key_down[] * Maybe called when keymap is undefined so that shift key release is seen */void compute_shiftstate(void){ int i, j, k, sym, val; shift_state = 0; for (i = 0; i < SIZE(k_down); i++) k_down[i] = 0; for (i = 0; i < SIZE(key_down); i++) if (key_down[i]) { /* skip this word if not a single bit on */ k = i * BITS_PER_LONG; for (j = 0; j < BITS_PER_LONG; j++, k++) if (test_bit (k, key_down)) { sym = U(plain_map[k]); if (KTYP(sym) == KT_SHIFT) { val = KVAL (sym); if (val == KVAL(K_CAPSSHIFT)) val = KVAL(K_SHIFT); k_down[val] ++; shift_state |= (1 << val); } } }}static void do_meta(unsigned char value, char up_flag){ if(up_flag) return; if(vc_kbd_mode(kbd, VC_META)) { put_queue ('\033'); put_queue (value); } else put_queue (value | 0x80);}static void do_ascii(unsigned char value, char up_flag){ int base; if (up_flag) return; if (value < 10) /* decimal input of code, while Alt depressed */ base = 10; else { /* hexadecimal input of code, while AltGr depressed */ value -= 10; base = 16; } if(npadch == -1) npadch = value; else npadch = npadch * base + value;}static void do_lock (unsigned char value, char up_flag){ if (up_flag || rep) return; chg_vc_kbd_lock (kbd, value);}static void do_slock (unsigned char value, char up_flag){ if (up_flag || rep) return; chg_vc_kbd_slock (kbd, value);}/* * The leds display either * (i) The status of NumLock, CapsLock and ScrollLock. * (ii) Whatever pattern of lights people wait to show using KDSETLED. * (iii) Specified bits of specified words in kernel memory. */static unsigned char ledstate = 0xff; /* undefined */static unsigned char ledioctl;unsigned char getledstate(void){ return ledstate;}void setledstate(struct kbd_struct *kbd, unsigned int led){ if(!(led & ~7)) { ledioctl = led; kbd->ledmode = LED_SHOW_IOCTL; } else kbd->ledmode = LED_SHOW_FLAGS; set_leds();}static struct ledptr { unsigned int *addr; unsigned int mask; unsigned char valid:1;} ledptrs[3];void register_leds(int console, unsigned int led, unsigned int *addr, unsigned int mask){ struct kbd_struct *kbd = vt_con_data[console].kbd; if(led < 3) { ledptrs[led].addr = addr; ledptrs[led].mask = mask; ledptrs[led].valid= 1; kbd->ledmode = LED_SHOW_MEM; } else kbd->ledmode = LED_SHOW_FLAGS;}static inline unsigned char getleds(void){ struct kbd_struct *kbd = vtdata.fgconsole->kbd; unsigned char leds; if(kbd->ledmode == LED_SHOW_IOCTL) return ledioctl; leds = kbd->ledflagstate; if (kbd->ledmode == LED_SHOW_MEM) { if (ledptrs[0].valid) { if (*ledptrs[0].addr & ledptrs[0].mask) leds |= 1; else leds &= ~1; } if (ledptrs[1].valid) { if (*ledptrs[1].addr & ledptrs[1].mask) leds |= 2; else leds &= ~2; } if (ledptrs[2].valid) { if(*ledptrs[2].addr & ledptrs[2].mask) leds |= 4; else leds &= ~4; } } return leds;}/* * This routine is the bottom half of the keyboard interrupt * routine, and runs with all interrupts enabled. It does * console changing, led setting and copy_to_cooked, which can * take a reasonably long time. * * Aside from timing (which isn't really that important for * keyboard interrupts as they happen often), using the software * interrupt routines for this thing allows us to easily mask * this when we don't want any of the above to happen. Not yet * used, but this allows for easy and efficient race-condition * prevention later on. */static void kbd_bh(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -