void keyPad()
{
	int erro=0, lado=1, opt=0;
	char key=0;
	Calculadora calc;

	iniciarVariaveis(&calc);
	atualizaTela(erro, opt, calc);

	while(key != 27)
	{
		erro=0;
		key = getch();

		if(key == 72)
		{
			moverCima(&opt, &lado);
			if(opt < 4)
				iniciarVariaveis(&calc);
		}
		else if(key == 80)
		{
			moverBaixo(&opt, &lado);
			if(opt < 5)	
				iniciarVariaveis(&calc);
		}
		else if(key == 75)
		{
			moverEsquerda(&opt, &lado);
		}
		else if(key == 77)
		{
			moverDireita(&opt, &lado);
		}
		else if(key == 8)
		{
			if(backspace(opt, &calc) == 1)
				iniciarConversao(opt, &calc);
			else if(opt < 4)
				iniciarVariaveis(&calc);
			else
				iniciarBinarioAS(&calc);
		}
		else
		{
			switch(opt)
			{
			case 0:
				keyDecimal(key, &erro, &calc);
				break;
			case 1:
				keyOctal(key, &erro, &calc);
				break;
			case 2:
				keyBinario(key, &erro, &calc);
				break;
			case 3:
				keyHexadecimal(key, &erro, &calc);
				break;
			case 4:
				keyBinarioAS(key, &erro, &calc, 1);
				break;
			case 5:
				keyBinarioAS(key, &erro, &calc, 2);
				break;
			}

			if(opt < 4)
				iniciarConversao(opt, &calc);
			else
				iniciarBinarioAS(&calc);
		}
		atualizaTela(erro, opt, calc);
	}
}
void CalculatorTestApp::handleKey(widgetid_t keyPressed) {

//  keyMap origKeyMap = (keyMap)buttons->getMap();

  switch (keyPressed) {
    case zero:
    case one:
    case two:
    case three:
    case four:
    case five:
    case six:
    case seven:
    case eight:
    case nine:
    case hex_a:
    case hex_b:
    case hex_c:
    case hex_d:
    case hex_e:
    case hex_f:
      keyDigit(keyPressed);
      break;
    case decimal:
      keyDecimal();
      break;
    case enter:
      keyEnter();
      break;
    case clear:
      keyClear();
      break;
    case backspace:
      keyBackspace();
      break;
    case shift:
      keyShift();
      break;
    case ee:
      keyEE();
      break;
    default:
      // the following are functions that accept the current input string
      acceptText();
      switch (keyPressed) {
      case divide:
        keyDivide();
        break;
      case multiply:
        keyMultiply();
        break;
      case add:
        keyAdd();
        break;
      case subtract:
        keySubtract();
        break;
      case inverse:
        keyInverse();
        break;
      case percent:
        keyPercent();
        break;
      case swap:
        keySwap();
        break;
      case changeBase:
        keyBase();
        break;
      case send:
        keySend();
        break;
      case square_f:
        keySquare();
        break;
      case cube_f:
        keyCube();
        break;
      case pow_f:
        keyPow();
        break;
      case exp_f:
        keyExp();
        break;
      case pow10_f:
        keyPow10();
        break;
      case sqrt_f:
        keySqrt();
        break;
      case cubert_f:
        keyCubert();
        break;
      case xroot_f:
        keyXroot();
        break;
      case ln_f:
        keyLn();
        break;
      case log10_f:
        keyLog10();
        break;
      case sin_f:
        keySin();
        break;
      case cos_f:
        keyCos();
        break;
      case tan_f:
        keyTan();
        break;
      case pi_f:
        keyPi();
        break;
      case e_f:
        keyE();
        break;
      case asin_f:
        keyAsin();
        break;
      case acos_f:
        keyAcos();
        break;
      case atan_f:
        keyAtan();
        break;
      case logy_f:
        keyLogy();
        break;
      case log2_f:
        keyLog2();
        break;
      case in2mm_f:
        keyIn2mm();
        break;
      case mm2in_f:
        keyMm2In();
        break;
      case g2lb_f:
        keyG2lb();
        break;
      case lb2g_f:
        keyLb2g();
        break;
      case c2f_f:
        keyC2f();
        break;
      case f2c_f:
        keyF2c();
        break;
      case ppi_f:
        keyPpi();
        break;
      default:
        break;
    }
  }

//  if (origKeyMap == sci_map && buttons->getMap() == sci_map) {
//    buttons->setMap(basic_map);
//  }

  drawDisplay();
}