int get_kbd_press(void) { int key; int buffer[10]; int *buf; if (esc_pending) { key = KY_ESC; esc_pending = 0; } else { key = vga_getkey(); if (key == KY_ERASE) key = KY_BACK; if (key != KY_ESC) return key; } /* Key == Esc look for special key */ buf = buffer; while((key=vga_getkey()) != 0) { if (key == KY_ESC) { esc_pending = 1; break;} else *buf++ = key; } *buf = '\0'; buf = buffer; /* Meta key of simple Esc */ if ((key=*buf++) != 0x5b) return key ? 0x200 | key : KY_ESC; /* Arrow keys */ if ((key=*buf++) != 0x5b) return 0x100 | key; /* Functional keys (F...) */ return 0x300 | *buf; }
// poll user events int gmPollEvents() { static int firstRun = 1; int rc = 0; // return code if (firstRun) { firstRun = 0; } char alph = vga_getkey(); while (alph) { // key loop switch (alph) { case 'q': case 'Q': case 27: { rc = 1; break; } default: // TODO : Mouse not supported yet break; } // switch alph = vga_getkey(); } // loop return rc; }
void client_main_loop (void) { int quit = 0; int engine_updated = 0; /* Set up the game */ reset_start_time (); update_avail_modules (0); screen_full_refresh (); if (no_init_help == 0) { block_help_exit = 1; help_flag = 1; if (make_dir_ok_flag) { activate_help ("ask-dir.hlp"); make_dir_ok_flag = 0; } else { activate_help ("opening.hlp"); } } /* Set speed */ #if defined (CS_PROFILE) || defined (START_FAST_SPEED) select_fast (); #else select_medium (); #endif /* Main Loop */ do { int key; /* Get timestamp for this iteration */ get_real_time(); /* Process events */ #if defined (LC_X11) call_event (); key = x_key_value; x_key_value = 0; #elif defined (WIN32) call_event (); key = GetKeystroke (); #else mouse_update (); key = vga_getkey (); #endif /* nothing happened if key == 0 XXX: right? */ /* GCS: I'm not sure */ if (key != 0) { process_keystrokes (key); } /* Simulate the timestep */ quit = execute_timestep (); } while (quit == 0); }
int get_svga_message(void) { if ((savechar = vga_getkey())) return GuiKeyboardEvent; if (mouse_update()) return GuiMouseEvent; return FALSE; }
int main(int argc, char *argv[]) { int i; int oldmode; int mode = G320x200x256; int width, height, colors; //获得当前的模式 oldmode = vga_getcurrentmode(); //初始化 vga_init(); //判断是否支持该模式 if(vga_hasmode(mode)) vga_setmode(mode); else { printf("No such mode\n"); exit(1); } //取得信息 width = vga_getxdim(); height = vga_getydim(); colors = vga_getcolors(); //绘图 for(i=0; i<colors; i++){ vga_setcolor(i); vga_drawline(0, i, width-1, i); } vga_setcolor(3); for(i=0; i<50; i++) vga_drawpixel(i*4, 20); vga_setcolor(4); vga_drawline(100, 100, 300, 200); vga_setcolor(5); vga_drawline(0, 0, width-1, 0); vga_drawline(0, height-1, width-1, height-1); vga_drawline(0, 0, 0, height-1); vga_drawline(width-1, 0, width-1, height-1); //等待按键 while(!vga_getkey()); //恢复原来的模式 vga_setmode(oldmode); return 0; }
/* * Check for "events" * If block, then busy-loop waiting for event, else check once and exit. */ static errr CheckEvents(int block) { int k = 0; if (block) { k = vga_getkey(); if (k < 1) return (1); } else { k = vga_getch(); } Term_keypress(k); return (0); }
void demo1(void) { int x, y; int targetx, targety; int pageoffset[3] = { 0, 320 * 240 / 4, 2 * 320 * 240 / 4 }; int writepage; int count, startclock; /* Window coordinate initially at center. */ x = VWIDTH / 2 - WINWIDTH / 2; y = VHEIGHT / 2 - WINHEIGHT / 2; targetx = x; targety = y; /* Page flipping initialization. */ vga_setdisplaystart(0); /* Display page 0, write to page 1. */ writepage = 1; count = 0; startclock = clock(); for (;;) { /* Copy window to screen. */ vga_copytoplanar256(vbuf + y * WIDTH + x, WIDTH, pageoffset[writepage], 80, WINWIDTH, WINHEIGHT); /* Flip pages. */ vga_setdisplaystart(pageoffset[writepage] * 4); #ifndef TRIPLEBUFFERING /* Conventional double-buffering (page-flipping). */ vga_waitretrace(); writepage ^= 1; #else /* Triple buffering; no need to wait for vertical retrace. */ writepage = (writepage + 1) % 3; #endif if (x == targetx && y == targety) { /* Create new target. */ targetx = rand() % (VWIDTH - WINWIDTH); targety = rand() % (VHEIGHT - WINHEIGHT); } /* Move towards target. */ if (x < targetx) x++; if (x > targetx) x--; if (y < targety) y++; if (y > targety) y--; /* Boundary checks. */ if (x < 0) x = 0; if (x > VWIDTH - WINWIDTH) x = VWIDTH - WINWIDTH; if (y < 0) y = 0; if (y > VHEIGHT - WINHEIGHT) y = VHEIGHT - WINHEIGHT; if (vga_getkey()) break; count++; } printf("Method 1: frame rate %ld\n", count * CLOCKS_PER_SEC / (clock() - startclock)); }
void demo3(void) { int x, y; int targetx, targety; int count, startclock; GraphicsContext *virtualscreen; GraphicsContext *physicalscreen; /* Window coordinate initially at center. */ x = VWIDTH / 2 - WINWIDTH / 2; y = VHEIGHT / 2 - WINHEIGHT / 2; targetx = x; targety = y; virtualscreen = gl_allocatecontext(); gl_getcontext(virtualscreen); gl_setcontextvga(G320x200x256); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); gl_setcontext(virtualscreen); count = 0; startclock = clock(); for (;;) { vga_waitretrace(); /* Copy window to screen. */ gl_copyboxtocontext(x, y, WINWIDTH, WINHEIGHT, physicalscreen, 0, 0); if (x == targetx && y == targety) { /* Create new target. */ targetx = rand() % (VWIDTH - WINWIDTH); targety = rand() % (VHEIGHT - WINHEIGHT); } /* Move towards target. */ if (x < targetx) x++; if (x > targetx) x--; if (y < targety) y++; if (y > targety) y--; /* Boundary checks. */ if (x < 0) x = 0; if (x > VWIDTH - WINWIDTH) x = VWIDTH - WINWIDTH; if (y < 0) y = 0; if (y > VHEIGHT - WINHEIGHT) y = VHEIGHT - WINHEIGHT; if (vga_getkey()) break; count++; } printf("Method 3: frame rate %ld\n", count * CLOCKS_PER_SEC / (clock() - startclock)); }
void demo2(void) { int x, y; int targetx, targety; int vwidth, vheight; int count, startclock; /* Make sure window fits in video memory. */ vwidth = VWIDTH; if (vwidth > 640) vwidth = 640; vheight = VHEIGHT; if (vheight > 400) vheight = 400; vga_setlogicalwidth(vwidth); /* Copy virtual screen to logical screen in video memory. */ vga_copytoplanar256(vbuf, VWIDTH, 0, vwidth / 4, vwidth, VHEIGHT); /* Window coordinates initially at center. */ x = vwidth / 2 - WINWIDTH / 2; y = vheight / 2 - WINHEIGHT / 2; targetx = x; targety = y; count = 0; startclock = clock(); for (;;) { /* Set video memory window. */ vga_setdisplaystart((y * vwidth / 4) * 4 + x); vga_waitretrace(); if (x == targetx && y == targety) { /* Create new target. */ targetx = rand() % (vwidth - WINWIDTH); targety = rand() % (vheight - WINHEIGHT); } /* Move towards target. */ if (x < targetx) x++; if (x > targetx) x--; if (y < targety) y++; if (y > targety) y--; /* Boundary checks. */ if (x < 0) x = 0; if (x > vwidth - WINWIDTH) x = vwidth - WINWIDTH; if (y < 0) y = 0; if (y > vheight - WINHEIGHT) y = vheight - WINHEIGHT; if (vga_getkey()) break; count++; } printf("Method 2: frame rate %ld\n", count*CLOCKS_PER_SEC /(clock() - startclock)); }
void si_scroll_text (void) { char s[LC_PATH_MAX], line1[100], line2[100], line3[100], c; int i, t, l1c = 0, l2c = 0, l3c = 0; FILE *inf1, *inf2, *inf3; #ifdef LC_X11 XEvent xev; #endif Fgl_enableclipping (); sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "text1"); if ((inf1 = fopen (s, "rb")) == NULL) do_error ("Can't open opening/text1"); for (i = 0; i < 52; i++) line1[i] = si_next_char (inf1); line1[52] = 0; sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "text2"); if ((inf2 = fopen (s, "rb")) == NULL) do_error ("Can't open opening/text2"); for (i = 0; i < 52; i++) line2[i] = si_next_char (inf2); line2[52] = 0; sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "text3"); if ((inf3 = fopen (s, "rb")) == NULL) do_error ("Can't open opening/text3"); for (i = 0; i < 52; i++) line3[i] = si_next_char (inf3); line3[52] = 0; do { get_real_time (); t = real_time + SPLASH_SCROLL_DELAY; #ifdef LC_X11 if (XPending (display.dpy)) { XNextEvent (display.dpy, &xev); HandleEvent (&xev); } c = x_key_value; #elif defined (WIN32) c = GetKeystroke (); #elif defined LC_SVGA c = vga_getkey (); #endif if (l1c >= 8) { for (i = 0; i < 51; i++) line1[i] = line1[i + 1]; line1[51] = si_next_char (inf1); l1c = 0; } Fgl_setfont (8, 8, start_font1); Fgl_setclippingwindow (120, 30, 520, 40); Fgl_setfontcolors (SI_BLACK, SI_RED); #if defined (LC_X11) || defined (WIN32) open_write (120 - l1c, 31, line1); #else Fgl_write (120 - l1c, 31, line1); #endif l1c++; if (l2c >= 8) { for (i = 0; i < 51; i++) line2[i] = line2[i + 1]; line2[51] = si_next_char (inf2); l2c = 0; } Fgl_setfont (8, 16, start_font2); Fgl_setclippingwindow (120, 55, 520, 73); Fgl_setfontcolors (SI_BLACK, SI_GREEN); #if defined (LC_X11) || defined (WIN32) open_write (120 - l2c, 57, line2); #else Fgl_write (120 - l2c, 57, line2); #endif l2c += 2; if (l3c >= 8) { for (i = 0; i < 51; i++) line3[i] = line3[i + 1]; line3[51] = si_next_char (inf3); l3c = 0; } Fgl_setfont (8, 16, start_font3); Fgl_setclippingwindow (120, 88, 520, 106); Fgl_setfontcolors (SI_BLACK, SI_YELLOW); #if defined (LC_X11) || defined (WIN32) open_write (120 - l3c, 90, line3); #else Fgl_write (120 - l3c, 90, line3); #endif l3c += 2; #if defined (WIN32) /* Scroll a little faster for WIN32 */ if (pix_double) { l1c += 10; l2c += 10; l3c += 10; } else { l1c += 2; l2c += 4; l3c += 4; } #endif while (real_time < t) { lc_usleep (1); get_real_time (); } } while (c == 0); fclose (inf1); fclose (inf2); fclose (inf3); Fgl_disableclipping (); }
void flush_kbd(void) { while (vga_getkey()); }
/*------------------------------------------------------------------------------ FUNCTION NAME: mael_getch DESCRIPTION: Realiza la lectura del buffer de teclado utilizando vga_getkey (SVGALIB_MODE) o XDisp_GetKey (XLIB_MODE). La rutina sabe de que manera debe leer cada tecla especial segun los scancodes devueltos por el driver de teclado bajo Linux. Por ejemplo: * Teclas de Función Reconoce el tercer caracter y desecha el cuarto si es que hay. <F1>: 27 - 91 - 91 - 65 <F2>: 27 - 91 - 91 - 66 <F3>: 27 - 91 - 91 - 67 <F4>: 27 - 91 - 91 - 68 <F5>: 27 - 91 - 91 - 69 <F6>: 27 - 91 - 49 - 55 - 126 <F7>: 27 - 91 - 49 - 56 - 126 <F8>: 27 - 91 - 49 - 57 - 126 * Teclas de Cursor Reconoce el tercer caracter. <UP> 27 - 91 - 65 <RIGHT> 27 - 91 - 67 <DOWN> 27 - 91 - 66 <LEFT> 27 - 91 - 68 * Otras teclas que devuelven mas de un caracter Reconoce el tercer caracter y desecha el cuarto. <CE> 27 - 91 - 51 - 126 La rutina realiza la lectura del buffer de teclado y almacena en la variable "SpecialFlag" una de las siguientes constantes: MAEL_KEY_NORMAL : Se presiono una tecla que se evalua con una sola lectura. ej: GAME (71); PRINT (80); 0..9 (40..57); etc. MAEL_KEY_CURSOR : Se presiono una tecla que se evalua con una tercer lectura. ej: UP 27 - 91 - 65 CE 27 - 91 - 51 - 126 MAEL_KEY_FUNCTION: Se presiono una tecla que se evalua con una tercer o cuarta lectura. ej: F1 27 - 91 - 91 - 65 F6 27 - 91 - 49 - 55 - 126 Luego de leer el teclado una, dos, tres o cuatro veces, almacena en la variable "KeyReaded" el código de la tecla presionada. Luego segun el SpecialFlag, evalúa que tecla se presionó y que código debe retornar para dicha tecla. Las constantes definidas para el (los) teclados se encuentran en KB.H Estas constantes se nomenclaron como: MAEL_KEY_XXXXXX_VALUE : Contiene el valor reconocido, devuelto por el driver de teclado del SO. MAEL_KEY_XXXXXX_RETURN: Contiene el valor que debe ser devuelto al Caller de la función. Ej: #define MAEL_KEY_FUNC_F1_VALUE 65 #define MAEL_KEY_FUNC_F1_RETURN 1 PARAMETERS: - INPUT : void - OUTPUT: RETURN : (int) KeyPresed NOTES : ------------------------------------------------------------------------------*/ int mael_getch(void) { int KeyReaded; int Ret; int SpecialKey, SpecialFlag; int fooKey; #if defined (XLIB_MODE) int Keysym; #endif /* Lectura de teclas */ KeyReaded = 0; SpecialKey = 0; /* Retorno de la funcion */ Ret = 0; /* Inicializa el tipo de tecla que leerá del buffer */ SpecialFlag = MAEL_KEY_NORMAL; /* Primer GetKey */ /* ------------- */ /* Si comienza con ESC puede haberse presionado: */ /* - Una tecla de función <F1> .. <FN> */ /* - Una tecla de Cursor */ /* - <CE> */ /* - <ESC> */ #if defined (SVGALIB_MODE) KeyReaded = vga_getkey(); #elif defined (XLIB_MODE) KeyReaded = XDisp_GetKey(&Keysym); #endif #if defined (KEYBOARD_DEBUG) if ((KeyReaded != 0) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "1 - KeyReaded (%d) KeySym (%d)", KeyReaded, Keysym); Util_DebugLog(sAux); } #endif if (KeyReaded == MAEL_KEY_ESC_VALUE) { /* Segundo GetKey */ /* -------------- */ /* Si viene un código 91 puede haberse presionado: */ /* - Una tecla de función <F1> .. <FN> */ /* - Una tecla de Cursor */ /* - <CE> */ /* Si no es 91, se presionó la tecla <ESC> y el */ /* código 27 es devuelto en KeyReaded. */ #if defined (SVGALIB_MODE) SpecialKey = vga_getkey(); #elif defined (XLIB_MODE) SpecialKey = XDisp_GetKey(&Keysym); #endif #if defined (KEYBOARD_DEBUG) if ((SpecialKey != 0) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "2 - KeyReaded (%d) KeySym (%d)", SpecialKey, Keysym); Util_DebugLog(sAux); } #endif if (SpecialKey == MAEL_KEY_91) { /* Tercer GetKey */ /* -------------- */ /* Controla si se presionó alguna tecla de cursor */ /* o <CE>. Si esta última fue presionada, vuelve a */ /* leer para descartar el cuarto caracter. */ /* Almacena SpecialFlag como MAEL_KEY_CURSOR */ #if defined (SVGALIB_MODE) SpecialKey = vga_getkey(); #elif defined (XLIB_MODE) SpecialKey = XDisp_GetKey(&Keysym); #endif #if defined (KEYBOARD_DEBUG) if ((SpecialKey != 0) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "3 - KeyReaded (%d) KeySym (%d)", SpecialKey, Keysym); Util_DebugLog(sAux); } #endif if (SpecialKey == MAEL_KEY_CURSOR_UP_VALUE || SpecialKey == MAEL_KEY_CURSOR_RIGHT_VALUE || SpecialKey == MAEL_KEY_CURSOR_DOWN_VALUE || SpecialKey == MAEL_KEY_CURSOR_LEFT_VALUE || SpecialKey == MAEL_KEY_CE_VALUE) { /* Se leyo una tecla de Cursor o CE (que tambien devuelve el 3er caracter luego del 27 y 91) */ SpecialFlag = MAEL_KEY_CURSOR; KeyReaded = SpecialKey; /* La tecla CE devuelve el caracter 126 en 4ta posicion. Lo desecho. */ if (SpecialKey == MAEL_KEY_CE_VALUE) { #if defined (SVGALIB_MODE) fooKey = vga_getkey(); #elif defined (XLIB_MODE) fooKey = XDisp_GetKey(&Keysym); #endif #if defined (KEYBOARD_DEBUG) if ((fooKey) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "4 - KeyReaded (%d) KeySym (%d)", fooKey, Keysym); Util_DebugLog(sAux); } #endif } } /* Si no se leyó el codigo correspondiente a una tecla de cursor o CE */ /* espera encontrar otro 91 para reconocer <F1> a <F5>. */ else if (SpecialKey == MAEL_KEY_91) { /* Cuarto GetKey */ /* ------------- */ /* Espera encontrar el código correspondiente */ /* a <F1>..<F5>. */ /* Almacena MAEL_KEY_FUNCTION en SpecialFlag. */ #if defined (SVGALIB_MODE) SpecialKey = vga_getkey(); #elif defined (XLIB_MODE) SpecialKey = XDisp_GetKey(&Keysym); #endif #if defined (KEYBOARD_DEBUG) if ((SpecialKey != 0) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "5 - KeyReaded (%d) KeySym (%d)", SpecialKey, Keysym); Util_DebugLog(sAux); } #endif if (SpecialKey == MAEL_KEY_FUNC_F1_VALUE || SpecialKey == MAEL_KEY_FUNC_F2_VALUE || SpecialKey == MAEL_KEY_FUNC_F3_VALUE || SpecialKey == MAEL_KEY_FUNC_F4_VALUE || SpecialKey == MAEL_KEY_FUNC_F5_VALUE) { SpecialFlag = MAEL_KEY_FUNCTION; KeyReaded = SpecialKey; } } /* Si no se leyó tampoco el codigo 91, espera recuperar un 49 */ /* correspondiente a las teclas de función <F6>, <F7> o <F8>. */ else if (SpecialKey == MAEL_KEY_49) { /* Cuarto GetKey */ /* ------------- */ /* Espera encontrar el código correspondiente */ /* a <F6>, <F7> o <F8>. */ /* Almacena MAEL_KEY_FUNCTION en SpecialFlag. */ #if defined (SVGALIB_MODE) SpecialKey = vga_getkey(); #elif defined (XLIB_MODE) SpecialKey = XDisp_GetKey(&Keysym); #endif #if defined (KEYBOARD_DEBUG) if ((SpecialKey != 0) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "6 - KeyReaded (%d) KeySym (%d)", SpecialKey, Keysym); Util_DebugLog(sAux); } #endif if (SpecialKey == MAEL_KEY_FUNC_F6_VALUE || SpecialKey == MAEL_KEY_FUNC_F7_VALUE || SpecialKey == MAEL_KEY_FUNC_F8_VALUE) { SpecialFlag = MAEL_KEY_FUNCTION; KeyReaded = SpecialKey; /* Las teclas F6, F7 y F8 devuelve el caracter 126 en 4ta posicion. Lo desecho. */ #if defined (SVGALIB_MODE) fooKey = vga_getkey(); #elif defined (XLIB_MODE) fooKey = XDisp_GetKey(&Keysym); #endif #if defined (KEYBOARD_DEBUG) if ((fooKey != 0) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "7 - KeyReaded (%d) KeySym (%d)", fooKey, Keysym); Util_DebugLog(sAux); } #endif } } /* Si el 3er GetKey no es ni 91 o 49 para F's, Retorna la lectura. No deberia entrar nunca a este Else */ /* ya que no hay Key's en la MAEL que macheen con esta condicion */ else { KeyReaded = SpecialKey; } } } /* Unico caso especial extra: 194 - 191, es originalmente la tecla = de MAEL */ /* Pero como dichos valores no caben dentro de un signed int, las constantes */ /* poseen el valor negativo: -62 y -65 */ else if (KeyReaded == MAEL_KEY_194) { #if defined (SVGALIB_MODE) SpecialKey = vga_getkey(); #elif defined (XLIB_MODE) SpecialKey = XDisp_GetKey(&Keysym); #endif #if defined (KEYBOARD_DEBUG) if ((SpecialKey != 0) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "8 - KeyReaded (%d) KeySym (%d)", SpecialKey, Keysym); Util_DebugLog(sAux); } #endif if (SpecialKey == MAEL_KEY_EQUAL_VALUE) { KeyReaded = SpecialKey; } } #if defined (XLIB_MODE) /* XLIB Functions Keys */ else if (Keysym == XLIB_KEY_F1_VALUE) return MAEL_KEY_FUNC_F1_RETURN; else if (Keysym == XLIB_KEY_F2_VALUE) return MAEL_KEY_FUNC_F2_RETURN; else if (Keysym == XLIB_KEY_F3_VALUE) return MAEL_KEY_FUNC_F3_RETURN; else if (Keysym == XLIB_KEY_F4_VALUE) return MAEL_KEY_FUNC_F4_RETURN; else if (Keysym == XLIB_KEY_F5_VALUE) return MAEL_KEY_FUNC_F5_RETURN; else if (Keysym == XLIB_KEY_F6_VALUE) return MAEL_KEY_FUNC_F6_RETURN; else if (Keysym == XLIB_KEY_F7_VALUE) return MAEL_KEY_FUNC_F7_RETURN; else if (Keysym == XLIB_KEY_F8_VALUE) return MAEL_KEY_FUNC_F8_RETURN; else if (Keysym == XLIB_KEY_F9_VALUE) /* RFS 1141 - Leo_20120911_1703 * Game key definition */ return MAEL_KEY_FUNC_F9_RETURN; /*return MAEL_KEY_FUNC_F9_RETURN;*/ else if (Keysym == XLIB_KEY_F10_VALUE) return LINUX_KEY_FUNC_F10_RETURN; else if (Keysym == XLIB_KEY_F11_VALUE) return LINUX_KEY_FUNC_F11_RETURN; /* XLIB Arrows Keys */ else if (Keysym == XLIB_KEY_RIGHT_VALUE) return MAEL_KEY_CURSOR_RIGHT_RETURN; else if (Keysym == XLIB_KEY_UP_VALUE) return MAEL_KEY_CURSOR_UP_RETURN; else if (Keysym == XLIB_KEY_LEFT_VALUE) return MAEL_KEY_CURSOR_LEFT_RETURN; else if (Keysym == XLIB_KEY_DOWN_VALUE) return MAEL_KEY_CURSOR_DOWN_RETURN; /* XLIB Numeric Keyboard Plus and Minus Keys */ else if (Keysym == XLIB_KEY_PLUS_VALUE) return MAEL_KEY_CONTRAST_UP_RETURN; else if (Keysym == XLIB_KEY_MINUS_VALUE) return MAEL_KEY_CONTRAST_DOWN_RETURN; /* XLIB Plus and Minus Keys */ else if (KeyReaded == XLIB_KEY_ALTERNATIVE_PLUS_VALUE) return MAEL_KEY_CONTRAST_UP_RETURN; else if (KeyReaded == XLIB_KEY_ALTERNATIVE_MINUS_VALUE) return MAEL_KEY_CONTRAST_DOWN_RETURN; else if (Keysym == XLIB_KEY_SHIFT_VALUE) { SpecialKey = XDisp_GetKey(&Keysym); #if defined (KEYBOARD_DEBUG) if ((SpecialKey != 0) || (Keysym !=0)) { char sAux[50]; sprintf(sAux, "9 - KeyReaded (%d) KeySym (%d)", SpecialKey, Keysym); Util_DebugLog(sAux); } #endif if (SpecialKey == KB_KEY_1) return 33; } #endif /* Según que tipo de tecla fue presionada, chequea que valor debe devolver para cada una. */ /* Esta tarea se realiza de esta manera ya que varias teclas tienen el mismo código. */ /* Por Ejemplo: */ /* <F1>: 27 - 91 - 91 - 65 y <ANN>: 65 */ /* Es por esto que F1 es del tipo MAEL_KEY_FUNCTION y <ANN> MAEL_NORMAL_KEY */ if (SpecialFlag == MAEL_KEY_CURSOR) { /* Teclas a traducir en la tercer leída */ switch(KeyReaded) { /* Key Up */ case MAEL_KEY_CURSOR_UP_VALUE: Ret = MAEL_KEY_CURSOR_UP_RETURN; break; /* Key DOWN */ case MAEL_KEY_CURSOR_DOWN_VALUE: Ret = MAEL_KEY_CURSOR_DOWN_RETURN; break; /* Key LEFT */ case MAEL_KEY_CURSOR_LEFT_VALUE: Ret = MAEL_KEY_CURSOR_LEFT_RETURN; break; /* Key RIGHT */ case MAEL_KEY_CURSOR_RIGHT_VALUE: Ret = MAEL_KEY_CURSOR_RIGHT_RETURN; break; /* Key CE - Infiltrada */ case MAEL_KEY_CE_VALUE: Ret = MAEL_KEY_CE_RETURN; break; default: Ret = KeyReaded; break; } } else if (SpecialFlag == MAEL_KEY_FUNCTION) { switch(KeyReaded) { /* Key F1 */ case MAEL_KEY_FUNC_F1_VALUE: Ret = MAEL_KEY_FUNC_F1_RETURN; break; /* Key F2 */ case MAEL_KEY_FUNC_F2_VALUE: Ret = MAEL_KEY_FUNC_F2_RETURN; break; /* Key F3 */ case MAEL_KEY_FUNC_F3_VALUE: Ret = MAEL_KEY_FUNC_F3_RETURN; break; /* Key F4 */ case MAEL_KEY_FUNC_F4_VALUE: Ret = MAEL_KEY_FUNC_F4_RETURN; break; /* Key F5 */ case MAEL_KEY_FUNC_F5_VALUE: Ret = MAEL_KEY_FUNC_F5_RETURN; break; /* Key F6 */ case MAEL_KEY_FUNC_F6_VALUE: Ret = MAEL_KEY_FUNC_F6_RETURN; break; /* Key F7 */ case MAEL_KEY_FUNC_F7_VALUE: Ret = MAEL_KEY_FUNC_F7_RETURN; break; /* Key F8 */ case MAEL_KEY_FUNC_F8_VALUE: Ret = MAEL_KEY_FUNC_F8_RETURN; break; /* Key F9 */ case MAEL_KEY_FUNC_F9_VALUE: Ret = MAEL_KEY_FUNC_F9_RETURN; break; default: Ret = KeyReaded; break; } } else { /* Teclas a traducir luego de la primer leída, retorna el código de tecla que espera */ /* la aplicación y que esta mapeada en la base de datos */ switch(KeyReaded) { /* Key ENTER */ case MAEL_KEY_ENTER_VALUE: Ret = MAEL_KEY_ENTER_RETURN; break; /* Key ANN */ case MAEL_KEY_ANN_VALUE: Ret = MAEL_KEY_ANN_RETURN; break; /* Key PRINT */ case MAEL_KEY_PRINT_VALUE: Ret = MAEL_KEY_PRINT_RETURN; break; /* Key BACKSPACE */ case MAEL_KEY_BACKSPACE_VALUE: Ret = MAEL_KEY_BACKSPACE_RETURN; break; /* Key DECIMAL DOT */ case MAEL_KEY_DECIMAL_VALUE: Ret = MAEL_KEY_DECIMAL_RETURN; break; /* Key MENU */ case MAEL_KEY_MENU_VALUE: Ret = MAEL_KEY_MENU_RETURN; break; /* Key QUICK */ case MAEL_KEY_QUICK_VALUE: Ret = MAEL_KEY_QUICK_RETURN; break; /* Key WIN */ case MAEL_KEY_WIN_VALUE: Ret = MAEL_KEY_WIN_RETURN; break; /* Key GAME */ case MAEL_KEY_GAME_VALUE: Ret = MAEL_KEY_GAME_RETURN; break; /* Key TOTAL */ case MAEL_KEY_TOTAL_VALUE: Ret = MAEL_KEY_TOTAL_RETURN; break; /* Key TAB */ case MAEL_KEY_TAB_VALUE: Ret = MAEL_KEY_TAB_RETURN; break; /* Key % */ case MAEL_KEY_PERCENT_VALUE: Ret = MAEL_KEY_PERCENT_RETURN; break; /* Key / */ case MAEL_KEY_SLASH_VALUE: Ret = MAEL_KEY_SLASH_RETURN; break; /* Key = */ case MAEL_KEY_EQUAL_VALUE: Ret = MAEL_KEY_EQUAL_RETURN; break; /* Key + */ case MAEL_KEY_PLUS_VALUE: Ret = MAEL_KEY_PLUS_RETURN; break; /* Key - */ case MAEL_KEY_MINUS_VALUE: Ret = MAEL_KEY_MINUS_RETURN; break; /* Key * */ case MAEL_KEY_ASTERISC_VALUE: Ret = MAEL_KEY_ASTERISC_RETURN; break; default: Ret = KeyReaded; break; } } return Ret; } /* mael_getch */
void process_keystrokes (int key) { #if defined (commentout) /* KBR 10/14/2002 - Cleanup MSVC warning */ int retval; #endif switch (key) { case 0: printf("dead!"); return; case ' ': /* Space */ case 10: /* Linefeed/Return */ case 13: /* Enter */ case 127: /* Backspace */ if (key == 127) { cs_mouse_handler (LC_MOUSE_RIGHTBUTTON | LC_MOUSE_PRESS, 0, 0); cs_mouse_handler (LC_MOUSE_RIGHTBUTTON | LC_MOUSE_RELEASE, 0, 0); } else { cs_mouse_handler (LC_MOUSE_LEFTBUTTON | LC_MOUSE_PRESS, 0, 0); cs_mouse_handler (LC_MOUSE_LEFTBUTTON | LC_MOUSE_RELEASE, 0, 0); } if (help_flag) { draw_help_page ("return-2"); } if (prefs_flag) { close_prefs_screen (); refresh_main_screen (); } break; #if defined (SVGALIB) case 91: { int w = vga_getkey (); switch (w) { case ('A'): cs_mouse_handler (0, 0, -kmouse_val); break; case ('B'): cs_mouse_handler (0, 0, kmouse_val); break; case ('C'): cs_mouse_handler (0, kmouse_val, 0); break; case ('D'): cs_mouse_handler (0, -kmouse_val, 0); break; } } break; #endif #if defined (WIN32) || defined (LC_X11) case 1: /* Scroll left */ if (x_key_shifted) { adjust_main_origin (main_screen_originx - RIGHT_MOUSE_MOVE_VAL, main_screen_originy, TRUE); } else { adjust_main_origin (main_screen_originx - 1, main_screen_originy, TRUE); } break; case 2: /* Scroll down */ if (x_key_shifted) { adjust_main_origin (main_screen_originx, main_screen_originy + RIGHT_MOUSE_MOVE_VAL, TRUE); } else { adjust_main_origin (main_screen_originx, main_screen_originy + 1, TRUE); } break; case 3: /* Scroll up */ if (x_key_shifted) { adjust_main_origin (main_screen_originx, main_screen_originy - RIGHT_MOUSE_MOVE_VAL, TRUE); } else { adjust_main_origin (main_screen_originx, main_screen_originy - 1, TRUE); } break; case 4: /* Scroll right */ if (x_key_shifted) { adjust_main_origin (main_screen_originx + RIGHT_MOUSE_MOVE_VAL, main_screen_originy, TRUE); } else { adjust_main_origin (main_screen_originx + 1, main_screen_originy, TRUE); } break; #endif case 'P': case 'p': select_pause (); break; #ifdef DEBUG_KEYS case 'e': if (cheat () != 0) people_pool += 100; break; case 'd': if (cheat () != 0) dump_screen (); break; case 'D': /* dump_tcore (); */ break; case 't': if (cheat () != 0) tech_level += 1000; break; case 'T': if (cheat () != 0) tech_level += 10000; break; case 'm': if (cheat () != 0) adjust_money(1000000); break; #endif case 'f': do_random_fire (-1, -1, 1); break; case 'L': case 'l': load_flag = 1; break; case 'H': case 'h': activate_help ("index.hlp"); break; /* Escape Key */ #ifdef LC_X11 case 27: #else case 5: #endif if (help_flag) { /* exit help */ draw_help_page("return-2"); } else if (prefs_flag) { close_prefs_screen(); refresh_main_screen (); } else { activate_help ("menu.hlp"); } break; case 'S': case 's': save_flag = 1; break; case 'v': case 'V': /* Toggle overlay */ rotate_main_screen(); break; case 'o': case 'O': prefs_flag = 1; break; case 'r': window_results(); break; case 'q': case 'Q': quit_flag = 1; break; } /* end switch on keystroke */ }