mek eet verk!

This commit is contained in:
Bill Currie 2001-08-16 17:52:35 +00:00
parent 12eff5eb65
commit 999c6a3b93

View file

@ -57,7 +57,7 @@ static int UseKeyboard = 1;
static int UseMouse = 1;
static int in_svgalib_inited = 0;
static unsigned short scantokey[128];
static unsigned short scantokey[3][128];
static int mouse_buttons;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
@ -65,17 +65,49 @@ static int mouse_oldbuttonstate;
static void IN_InitKeyboard (void);
static void IN_InitMouse (void);
#define ROTL(x,n) (((x)<<(n))|(x)>>(32-n))
static void
keyhandler (int scancode, int state)
{
int sc;
int key;
int ascii;
int press = state == KEY_EVENTPRESS;
unsigned long mask = ~1;
static unsigned long shifts;
sc = scancode & 0x7f;
#if 0
Con_Printf ("scancode=%x (%d%s)\n", scancode, sc,
scancode & 0x80 ? "+128" : "");
#endif
Key_Event (scantokey[sc], -1, state == KEY_EVENTPRESS);
key = scantokey[0][sc];
if ((shifts & 0xc)) {
ascii = scantokey[2][sc];
} else if (shifts & 3) {
ascii = scantokey[1][sc];
} else {
ascii = scantokey[0][sc];
}
if (ascii > 255)
ascii = 0;
switch (key) {
case K_RSHIFT:
shifts &= mask;
shifts |= press;
break;
case K_LSHIFT:
shifts &= ROTL(mask, 1);
shifts |= ROTL(press, 1);
break;
case K_RCTRL:
shifts &= ROTL(mask, 2);
shifts |= ROTL(press, 2);
break;
case K_LCTRL:
shifts &= ROTL(mask, 3);
shifts |= ROTL(press, 3);
break;
default:
}
Key_Event (key, ascii, press);
}
@ -86,11 +118,11 @@ mousehandler (int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz
in_mouse_x += dx;
in_mouse_y += dy;
if (drx > 0) {
Key_Event (K_MWHEELUP, 0, 1);
Key_Event (K_MWHEELUP, 0, 0);
Key_Event (M_WHEEL_UP, 0, 1);
Key_Event (M_WHEEL_UP, 0, 0);
} else if (drx < 0) {
Key_Event (K_MWHEELDOWN, 0, 1);
Key_Event (K_MWHEELDOWN, 0, 0);
Key_Event (M_WHEEL_DOWN, 0, 1);
Key_Event (M_WHEEL_DOWN, 0, 0);
}
}
@ -123,114 +155,197 @@ IN_InitKeyboard (void)
int i;
for (i = 0; i < 128; i++) {
scantokey[i] = ' ';
scantokey[0][i] = ' ';
}
scantokey[1] = K_ESCAPE;
scantokey[2] = '1';
scantokey[3] = '2';
scantokey[4] = '3';
scantokey[5] = '4';
scantokey[6] = '5';
scantokey[7] = '6';
scantokey[8] = '7';
scantokey[9] = '8';
scantokey[10] = '9';
scantokey[11] = '0';
scantokey[12] = '-';
scantokey[13] = '=';
scantokey[14] = K_BACKSPACE;
scantokey[15] = K_TAB;
scantokey[16] = 'q';
scantokey[17] = 'w';
scantokey[18] = 'e';
scantokey[19] = 'r';
scantokey[20] = 't';
scantokey[21] = 'y';
scantokey[22] = 'u';
scantokey[23] = 'i';
scantokey[24] = 'o';
scantokey[25] = 'p';
scantokey[26] = '[';
scantokey[27] = ']';
scantokey[28] = K_ENTER;
scantokey[29] = K_CTRL; /* left */
scantokey[30] = 'a';
scantokey[31] = 's';
scantokey[32] = 'd';
scantokey[33] = 'f';
scantokey[34] = 'g';
scantokey[35] = 'h';
scantokey[36] = 'j';
scantokey[37] = 'k';
scantokey[38] = 'l';
scantokey[39] = ';';
scantokey[40] = '\'';
scantokey[41] = '`';
scantokey[42] = K_SHIFT; /* left */
scantokey[43] = '\\';
scantokey[44] = 'z';
scantokey[45] = 'x';
scantokey[46] = 'c';
scantokey[47] = 'v';
scantokey[48] = 'b';
scantokey[49] = 'n';
scantokey[50] = 'm';
scantokey[51] = ',';
scantokey[52] = '.';
scantokey[53] = '/';
scantokey[54] = K_SHIFT; /* right */
scantokey[55] = KP_MULTIPLY;
scantokey[56] = K_ALT; /* left */
scantokey[57] = ' ';
scantokey[58] = K_CAPSLOCK;
scantokey[59] = K_F1;
scantokey[60] = K_F2;
scantokey[61] = K_F3;
scantokey[62] = K_F4;
scantokey[63] = K_F5;
scantokey[64] = K_F6;
scantokey[65] = K_F7;
scantokey[66] = K_F8;
scantokey[67] = K_F9;
scantokey[68] = K_F10;
scantokey[69] = KP_NUMLCK;
scantokey[70] = K_SCRLCK;
scantokey[71] = KP_HOME;
scantokey[72] = KP_UPARROW;
scantokey[73] = KP_PGUP;
scantokey[74] = KP_MINUS;
scantokey[75] = KP_LEFTARROW;
scantokey[76] = KP_5;
scantokey[77] = KP_RIGHTARROW;
scantokey[79] = KP_END;
scantokey[78] = KP_PLUS;
scantokey[80] = KP_DOWNARROW;
scantokey[81] = KP_PGDN;
scantokey[82] = KP_INS;
scantokey[83] = KP_DEL;
scantokey[0][1] = K_ESCAPE;
scantokey[0][2] = '1';
scantokey[0][3] = '2';
scantokey[0][4] = '3';
scantokey[0][5] = '4';
scantokey[0][6] = '5';
scantokey[0][7] = '6';
scantokey[0][8] = '7';
scantokey[0][9] = '8';
scantokey[0][10] = '9';
scantokey[0][11] = '0';
scantokey[0][12] = '-';
scantokey[0][13] = '=';
scantokey[0][14] = K_BACKSPACE;
scantokey[0][15] = K_TAB;
scantokey[0][16] = 'q';
scantokey[0][17] = 'w';
scantokey[0][18] = 'e';
scantokey[0][19] = 'r';
scantokey[0][20] = 't';
scantokey[0][21] = 'y';
scantokey[0][22] = 'u';
scantokey[0][23] = 'i';
scantokey[0][24] = 'o';
scantokey[0][25] = 'p';
scantokey[0][26] = '[';
scantokey[0][27] = ']';
scantokey[0][28] = K_RETURN;
scantokey[0][29] = K_LCTRL; /* left */
scantokey[0][30] = 'a';
scantokey[0][31] = 's';
scantokey[0][32] = 'd';
scantokey[0][33] = 'f';
scantokey[0][34] = 'g';
scantokey[0][35] = 'h';
scantokey[0][36] = 'j';
scantokey[0][37] = 'k';
scantokey[0][38] = 'l';
scantokey[0][39] = ';';
scantokey[0][40] = '\'';
scantokey[0][41] = '`';
scantokey[0][42] = K_LSHIFT; /* left */
scantokey[0][43] = '\\';
scantokey[0][44] = 'z';
scantokey[0][45] = 'x';
scantokey[0][46] = 'c';
scantokey[0][47] = 'v';
scantokey[0][48] = 'b';
scantokey[0][49] = 'n';
scantokey[0][50] = 'm';
scantokey[0][51] = ',';
scantokey[0][52] = '.';
scantokey[0][53] = '/';
scantokey[0][54] = K_RSHIFT; /* right */
scantokey[0][55] = K_KP_MULTIPLY;
scantokey[0][56] = K_LALT; /* left */
scantokey[0][57] = ' ';
scantokey[0][58] = K_CAPSLOCK;
scantokey[0][59] = K_F1;
scantokey[0][60] = K_F2;
scantokey[0][61] = K_F3;
scantokey[0][62] = K_F4;
scantokey[0][63] = K_F5;
scantokey[0][64] = K_F6;
scantokey[0][65] = K_F7;
scantokey[0][66] = K_F8;
scantokey[0][67] = K_F9;
scantokey[0][68] = K_F10;
scantokey[0][69] = K_NUMLOCK;
scantokey[0][70] = K_SCROLLOCK;
scantokey[0][71] = K_KP7;
scantokey[0][72] = K_KP8;
scantokey[0][73] = K_KP9;
scantokey[0][74] = K_KP_MINUS;
scantokey[0][75] = K_KP4;
scantokey[0][76] = K_KP5;
scantokey[0][77] = K_KP6;
scantokey[0][79] = K_KP1;
scantokey[0][78] = K_KP_PLUS;
scantokey[0][80] = K_KP2;
scantokey[0][81] = K_KP3;
scantokey[0][82] = K_KP0;
scantokey[0][83] = K_KP_PERIOD;
/* 84 to 86 not used */
scantokey[87] = K_F11;
scantokey[88] = K_F12;
scantokey[0][87] = K_F11;
scantokey[0][88] = K_F12;
/* 89 to 95 not used */
scantokey[96] = KP_ENTER; /* keypad enter */
scantokey[97] = K_CTRL; /* right */
scantokey[98] = KP_DIVIDE;
scantokey[99] = K_PRNTSCR; /* print screen */
scantokey[100] = K_ALT; /* right */
scantokey[0][96] = K_KP_ENTER; /* keypad enter */
scantokey[0][97] = K_RCTRL; /* right */
scantokey[0][98] = K_KP_DIVIDE;
scantokey[0][99] = K_PRINT; /* print screen */
scantokey[0][100] = K_RALT; /* right */
scantokey[101] = K_PAUSE; /* break */
scantokey[102] = K_HOME;
scantokey[103] = K_UPARROW;
scantokey[104] = K_PGUP;
scantokey[105] = K_LEFTARROW;
scantokey[106] = K_RIGHTARROW;
scantokey[107] = K_END;
scantokey[108] = K_DOWNARROW;
scantokey[109] = K_PGDN;
scantokey[110] = K_INS;
scantokey[111] = K_DEL;
scantokey[119] = K_PAUSE;
scantokey[0][101] = K_PAUSE; /* break */
scantokey[0][102] = K_HOME;
scantokey[0][103] = K_UP;
scantokey[0][104] = K_PAGEUP;
scantokey[0][105] = K_LEFT;
scantokey[0][106] = K_RIGHT;
scantokey[0][107] = K_END;
scantokey[0][108] = K_DOWN;
scantokey[0][109] = K_PAGEDOWN;
scantokey[0][110] = K_INSERT;
scantokey[0][111] = K_DELETE;
scantokey[0][119] = K_PAUSE;
memcpy (scantokey[1], scantokey[0], sizeof (scantokey[1]));
memcpy (scantokey[2], scantokey[0], sizeof (scantokey[2]));
scantokey[1][2] = '!';
scantokey[1][3] = '@';
scantokey[1][4] = '#';
scantokey[1][5] = '$';
scantokey[1][6] = '%';
scantokey[1][7] = '^';
scantokey[1][8] = '&';
scantokey[1][9] = '*';
scantokey[1][10] = '(';
scantokey[1][11] = ')';
scantokey[1][12] = '_';
scantokey[1][13] = '+';
scantokey[1][16] = 'Q';
scantokey[1][17] = 'W';
scantokey[1][18] = 'E';
scantokey[1][19] = 'R';
scantokey[1][20] = 'T';
scantokey[1][21] = 'Y';
scantokey[1][22] = 'U';
scantokey[1][23] = 'I';
scantokey[1][24] = 'O';
scantokey[1][25] = 'P';
scantokey[1][26] = '[';
scantokey[1][27] = ']';
scantokey[1][30] = 'A';
scantokey[1][31] = 'S';
scantokey[1][32] = 'D';
scantokey[1][33] = 'F';
scantokey[1][34] = 'G';
scantokey[1][35] = 'H';
scantokey[1][36] = 'J';
scantokey[1][37] = 'K';
scantokey[1][38] = 'L';
scantokey[1][39] = ':';
scantokey[1][40] = '"';
scantokey[1][41] = '~';
scantokey[1][43] = '|';
scantokey[1][44] = 'Z';
scantokey[1][45] = 'X';
scantokey[1][46] = 'C';
scantokey[1][47] = 'V';
scantokey[1][48] = 'B';
scantokey[1][49] = 'N';
scantokey[1][50] = 'M';
scantokey[1][51] = '<';
scantokey[1][52] = '>';
scantokey[1][53] = '?';
scantokey[1][7] = 30;
scantokey[1][12] = 31;
scantokey[2][16] = 'q' - 96;
scantokey[2][17] = 'w' - 96;
scantokey[2][18] = 'e' - 96;
scantokey[2][19] = 'r' - 96;
scantokey[2][20] = 't' - 96;
scantokey[2][21] = 'y' - 96;
scantokey[2][22] = 'u' - 96;
scantokey[2][23] = 'i' - 96;
scantokey[2][24] = 'o' - 96;
scantokey[2][25] = 'p' - 96;
scantokey[2][26] = 27;
scantokey[2][27] = 29;
scantokey[2][30] = 'a' - 96;
scantokey[2][31] = 's' - 96;
scantokey[2][32] = 'd' - 96;
scantokey[2][33] = 'f' - 96;
scantokey[2][34] = 'g' - 96;
scantokey[2][35] = 'h' - 96;
scantokey[2][36] = 'j' - 96;
scantokey[2][37] = 'k' - 96;
scantokey[2][38] = 'l' - 96;
scantokey[2][40] = 28;
scantokey[2][44] = 'z' - 96;
scantokey[2][45] = 'x' - 96;
scantokey[2][46] = 'c' - 96;
scantokey[2][47] = 'v' - 96;
scantokey[2][48] = 'b' - 96;
scantokey[2][49] = 'n' - 96;
scantokey[2][50] = 'm' - 96;
if (keyboard_init ()) {
Sys_Error ("keyboard_init() failed");
@ -309,24 +424,24 @@ IN_LL_Commands (void)
/* Perform button actions */
if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
Key_Event (K_MOUSE1, 0, true);
Key_Event (M_BUTTON1, 0, true);
else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
Key_Event (K_MOUSE1, 0, false);
Key_Event (M_BUTTON1, 0, false);
if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
Key_Event (K_MOUSE2, 0, true);
Key_Event (M_BUTTON2, 0, true);
else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
Key_Event (K_MOUSE2, 0, false);
Key_Event (M_BUTTON2, 0, false);
if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event (K_MOUSE3, 0, true);
Key_Event (M_BUTTON3, 0, true);
else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event (K_MOUSE3, 0, false);
Key_Event (M_BUTTON3, 0, false);
mouse_oldbuttonstate = mouse_buttonstate;
}