/* * keyboard interrupt */ static void i8042intr(Ureg*, void*) { int s, c, i; static int esc1, esc2; static int alt, caps, ctl, num, shift; static int collecting, nk; static Rune kc[5]; int keyup; /* * get status */ lock(&i8042lock); s = inb(Status); if(!(s&Inready)){ unlock(&i8042lock); return; } /* * get the character */ c = inb(Data); unlock(&i8042lock); /* * if it's the aux port... */ if(s & Minready){ if(auxputc != nil) auxputc(c, shift); return; } /* * e0's is the first of a 2 character sequence */ if(c == 0xe0){ esc1 = 1; return; } else if(c == 0xe1){ esc2 = 2; return; } keyup = c&0x80; c &= 0x7f; if(c > sizeof kbtab){ c |= keyup; if(c != 0xFF) /* these come fairly often: CAPSLOCK U Y */ print("unknown key %ux\n", c); return; } if(esc1){ c = kbtabesc1[c]; esc1 = 0; } else if(esc2){ esc2--; return; } else if(shift) c = kbtabshift[c]; else c = kbtab[c]; if(caps && c<='z' && c>='a') c += 'A' - 'a'; /* * keyup only important for shifts */ if(keyup){ switch(c){ case Latin: alt = 0; break; case Shift: shift = 0; break; case Ctrl: ctl = 0; break; } return; } /* * normal character */ if(!(c & (Spec|KF))){ if(ctl){ if(alt && c == Del) exit(0); c &= 0x1f; } if(!collecting){ kbdputc(kbdq, c); return; } kc[nk++] = c; c = latin1(kc, nk); if(c < -1) /* need more keystrokes */ return; if(c != -1) /* valid sequence */ kbdputc(kbdq, c); else /* dump characters */ for(i=0; i<nk; i++) kbdputc(kbdq, kc[i]); nk = 0; collecting = 0; return; } else { switch(c){ case Caps: caps ^= 1; return; case Num: num ^= 1; return; case Shift: shift = 1; return; case Latin: alt = 1; collecting = 1; nk = 0; return; case Ctrl: ctl = 1; return; } } kbdputc(kbdq, c); }
/* * keyboard interrupt */ static void i8042intr(Ureg*, void*) { int s, c, i; static int esc1, esc2; static int alt, caps, ctl, num, shift; static int collecting, nk; static Rune kc[5]; int keyup; /* * get status */ lock(&i8042lock); s = inb(Status); if(!(s&Inready)){ unlock(&i8042lock); return; } /* * get the character */ c = inb(Data); unlock(&i8042lock); /* * if it's the aux port... */ if(s & Minready){ if(auxputc != nil) auxputc(c, shift); return; } /* * e0's is the first of a 2 character sequence */ if(c == 0xe0){ esc1 = 1; return; } else if(c == 0xe1){ esc2 = 2; return; } keyup = c&0x80; c &= 0x7f; if(c > sizeof kbtab){ c |= keyup; if(c != 0xFF) /* these come fairly often: CAPSLOCK U Y */ print("unknown key %ux\n", c); return; } if(esc1){ c = kbtabesc1[c]; esc1 = 0; } else if(esc2){ esc2--; return; } else if(shift) c = kbtabshift[c]; else c = kbtab[c]; if(caps && c<='z' && c>='a') c += 'A' - 'a'; /* * keyup only important for shifts */ if(keyup){ switch(c){ case Latin: alt = 0; break; case Shift: shift = 0; mouseshifted = 0; break; case Ctrl: ctl = 0; break; } return; } /* * normal character */ if(!(c & (Spec|KF))){ if(ctl){ if(alt && c == Del) exit(0); c &= 0x1f; } if(!collecting){ kbdputc(kbdq, c); return; } kc[nk++] = c; c = latin1(kc, nk); if(c < -1) /* need more keystrokes */ return; if(c != -1) /* valid sequence */ kbdputc(kbdq, c); else /* dump characters */ for(i=0; i<nk; i++) kbdputc(kbdq, kc[i]); nk = 0; collecting = 0; return; } else { switch(c){ case Caps: caps ^= 1; return; case Num: num ^= 1; return; case Shift: shift = 1; mouseshifted = 1; return; case Latin: alt = 1; /* * VMware uses Ctl-Alt as the key combination * to make the VM give up keyboard and mouse focus. * This has the unfortunate side effect that when you * come back into focus, Plan 9 thinks you want to type * a compose sequence (you just typed alt). * * As a clumsy hack around this, we look for ctl-alt * and don't treat it as the start of a compose sequence. */ if(!ctl){ collecting = 1; nk = 0; } return; case Ctrl: collecting = 0; nk = 0; ctl = 1; return; } } kbdputc(kbdq, c); }