Advertisement
jacknpoe

Exemplo (ruim) de tratamento de teclas

Feb 13th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. // ###  A V I S O  ###
  2. // Os códigos abaixo são LEGADOS e feitos "pra funcionar" em momentos de desespero em compiladores antigos e
  3. // quando não haviam "engines" e documentação sobre o assunto. Não faça isso em casa
  4.  
  5. —————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  6. // ********** DROPS 2 - ZICAU SOFTWARE LIMITADA - ITAJAI, SC - 1994 - em C **********
  7. —————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  8.  
  9. void interrupt nova_int_09h()
  10. {
  11.     scancode = inportb( 0x60);
  12.     switch (scancode)
  13.     {
  14.         case  72: { if( estado_tecla[0] == 0) press_tecla[0] = 1;
  15.                     estado_tecla[0] = 1; }
  16.                     break;
  17.         case 200: { estado_tecla[0] = 0;
  18.                     tempo_tecla[0] = 0; }
  19.                     break;
  20.         case  77: { if( estado_tecla[1] == 0) press_tecla[1] = 1;
  21.                     estado_tecla[1] = 1; }
  22.                     break;
  23.         case 205: { estado_tecla[1] = 0;
  24.                     tempo_tecla[1] = 0; }
  25.                     break;
  26.         case  80: { if( estado_tecla[2] == 0) press_tecla[2] = 1;
  27.                     estado_tecla[2] = 1; }
  28.                     break;
  29.         case 208: { estado_tecla[2] = 0;
  30.                     tempo_tecla[2] = 0; }
  31.                     break;
  32.         case  75: { if( estado_tecla[3] == 0) press_tecla[3] = 1;
  33.                     estado_tecla[3] = 1; }
  34.                     break;
  35.         case 203: { estado_tecla[3] = 0;
  36.                     tempo_tecla[3] = 0; }
  37.                     break;
  38.     }
  39.     if( ( ( ( scancode > 70) & ( scancode < 82)) | ( ( scancode > 198) & ( scancode < 210))) | scancode == 225)
  40.     {
  41.         auxiliar = inportb( 0x61);
  42.         outportb( 0x61, auxiliar | 0x80);
  43.         outportb( 0x61, auxiliar);
  44.         outportb( 0x20, 0x20);
  45.     }
  46.     else (*velha_int_09h)();
  47. }
  48.  
  49.  
  50. void interrupt nova_int_1ch()
  51. {
  52.     hora_real++;
  53.  
  54.     if( estado_tecla[0] == 1)
  55.     {
  56.         tempo_tecla[0] += 1;
  57.         if( tempo_tecla[0] > 11)
  58.         {
  59.             tempo_tecla[0] -= 12;
  60.             press_tecla[0] = 1;
  61.         }
  62.     }
  63.     if( estado_tecla[1] == 1)
  64.     {
  65.         tempo_tecla[1] += 1;
  66.         if( tempo_tecla[1] > 8)
  67.         {
  68.             tempo_tecla[1] -= 9;
  69.             press_tecla[1] = 1;
  70.         }
  71.     }
  72.     if( estado_tecla[2] == 1)
  73.     {
  74.         tempo_tecla[2] += 1;
  75.         if( tempo_tecla[2] > 11)
  76.         {
  77.             tempo_tecla[2] -= 12;
  78.             press_tecla[2] = 1;
  79.         }
  80.     }
  81.     if( estado_tecla[3] == 1)
  82.     {
  83.         tempo_tecla[3] += 1;
  84.         if( tempo_tecla[3] > 8)
  85.         {
  86.             tempo_tecla[3] -= 9;
  87.             press_tecla[3] = 1;
  88.         }
  89.     }
  90.  
  91.     (*velha_int_1ch)();
  92. }
  93.  
  94.  
  95. EXEMPLO (MAL FEITO) DE USO:
  96.  
  97.     if( press_tecla[3] == 1)
  98.     {
  99.         pont = x_peca - 1;
  100.         if( bateu( pont, y_peca - 1) == 0)
  101.         {
  102.             tire( 112 + x_peca * 8, 16 + y_peca * 8);
  103.             x_peca = pont;
  104.             put_peca( 112 + x_peca * 8, 16 + y_peca * 8, peca1);
  105.         }
  106.         press_tecla[3] = 0;
  107.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement