
 ////////////
 //
FUNCTION espera_(nTime)
 //                  [<nTime>]  ->   0 or NIL waits until typing something
 //                             ->   0 waits <nTime> or that something being typed
 //                             -> < 0 - only checks if it has some pendenting key
 //                  Retorns nEventEquiv (converted from GUI to VIO) .or. 0
 /////
LOCAL nEvent, nEventEquiv, mp1, mp2, oXbp, bSet
if nTime == NIL
   nTime := 0
endif
do while .t.
   nEvent := AppEvent(@mp1, @mp2, @oXbp, nTime)
   if nEvent <> xbe_None
      if EventToVio_(nEvent, @nEventEquiv)
         bSet    := SetKey(nEventEquiv)
         if bSet <> NIL
            Eval(bSet)
            if nTime == 0
               loop
            endif
         endif
         exit
      else
         bSet    := SetAppEvent(nEvent)
         if bSet <> NIL
            Eval(bSet)
            if nTime == 0
               loop
            endif
         endif
      endif
      oXbp:handleEvent(nEvent, mp1, mp2)
   endif
   if nTime       <> 0
      nEventEquiv := 0
      exit
   endif
enddo
RETURN nEventEquiv

 ////////////
 //
FUNCTION EventToVio_(nEvent, nEventEquiv)
 //      Not all events are here and the order neither match to ApEvent.ch nor to InKey()
 //
 //      Return: .t. if nEvent was a AppEvent() converted to VIO. <nEventEquiv > will contain the InKey() key
 //              .f. if nEvent was not converted to VIO. <nEventEquiv> will contain the same as <nEvent>
 //               .f. se <nEvent> não foi modificado.
 /////
LOCAL nFound, lConverted,;
      aGuiEvents := {{xbeK_UP,               K_UP},;
                     {xbeK_DOWN,             K_DOWN},;
                     {xbeK_LEFT,             K_LEFT},;
                     {xbeK_RIGHT,            K_RIGHT},;
                     {xbeK_HOME,             K_HOME},;
                     {xbeK_END,              K_END},;
                     {xbeK_PGUP,             K_PGUP},;
                     {xbeK_PGDN,             K_PGDN},;
                     {xbeK_ENTER,            K_ENTER},;
                     {xbeK_RETURN,           K_RETURN},;
                     {xbeK_SPACE,            K_SPACE},;
                     {xbeK_ESC,              K_ESC},;
                     {xbeK_INS,              K_INS},;
                     {xbeK_DEL,              K_DEL},;
                     {xbeK_BS,               K_BS},;
                     {xbeK_CTRL_UP,          K_CTRL_UP},;
                     {xbeK_CTRL_DOWN,        K_CTRL_DOWN},;
                     {xbeK_CTRL_LEFT,        K_CTRL_LEFT},;
                     {xbeK_CTRL_RIGHT,       K_CTRL_RIGHT},;
                     {xbeK_CTRL_HOME,        K_CTRL_HOME},;
                     {xbeK_CTRL_END,         K_CTRL_END },;
                     {xbeK_CTRL_PGUP,        K_CTRL_PGUP},;
                     {xbeK_CTRL_PGDN,        K_CTRL_PGDN},;
                     {xbeK_TAB,              K_TAB   },;
                     {xbeK_SH_TAB,           K_SH_TAB},;
                     {xbeK_F1,               K_F1},;
                     {xbeK_F2,               K_F2},;
                     {xbeK_F3,               K_F3},;
                     {xbeK_F4,               K_F4},;
                     {xbeK_F5,               K_F5},;
                     {xbeK_F6,               K_F6},;
                     {xbeK_F7,               K_F7},;
                     {xbeK_F8,               K_F8},;
                     {xbeK_F9,               K_F9},;
                     {xbeK_F10,              K_F10},;
                     {xbeK_F11,              K_F11},;
                     {xbeK_F12,              K_F12},;
                     {xbeK_ALT_A,            K_ALT_A},;
                     {xbeK_ALT_B,            K_ALT_B},;
                     {xbeK_ALT_C,            K_ALT_C},;
                     {xbeK_ALT_D,            K_ALT_D},;
                     {xbeK_ALT_E,            K_ALT_E},;
                     {xbeK_ALT_F,            K_ALT_F},;
                     {xbeK_ALT_G,            K_ALT_G},;
                     {xbeK_ALT_H,            K_ALT_H},;
                     {xbeK_ALT_I,            K_ALT_I},;
                     {xbeK_ALT_J,            K_ALT_J},;
                     {xbeK_ALT_K,            K_ALT_K},;
                     {xbeK_ALT_L,            K_ALT_L},;
                     {xbeK_ALT_M,            K_ALT_M},;
                     {xbeK_ALT_N,            K_ALT_N},;
                     {xbeK_ALT_O,            K_ALT_O},;
                     {xbeK_ALT_P,            K_ALT_P},;
                     {xbeK_ALT_Q,            K_ALT_Q},;
                     {xbeK_ALT_R,            K_ALT_R},;
                     {xbeK_ALT_S,            K_ALT_S},;
                     {xbeK_ALT_T,            K_ALT_T},;
                     {xbeK_ALT_U,            K_ALT_U},;
                     {xbeK_ALT_V,            K_ALT_V},;
                     {xbeK_ALT_W,            K_ALT_W},;
                     {xbeK_ALT_X,            K_ALT_X},;
                     {xbeK_ALT_Y,            K_ALT_Y},;
                     {xbeK_ALT_Z,            K_ALT_Z},;
                     {xbeK_CTRL_A,           K_CTRL_A},;
                     {xbeK_CTRL_B,           K_CTRL_B},;
                     {xbeK_CTRL_C,           K_CTRL_C},;
                     {xbeK_CTRL_D,           K_CTRL_D},;
                     {xbeK_CTRL_E,           K_CTRL_E},;
                     {xbeK_CTRL_F,           K_CTRL_F},;
                     {xbeK_CTRL_G,           K_CTRL_G},;
                     {xbeK_CTRL_H,           K_CTRL_H},;
                     {xbeK_CTRL_I,           K_CTRL_I},;
                     {xbeK_CTRL_J,           K_CTRL_J},;
                     {xbeK_CTRL_K,           K_CTRL_K},;
                     {xbeK_CTRL_L,           K_CTRL_L},;
                     {xbeK_CTRL_M,           K_CTRL_M},;
                     {xbeK_CTRL_N,           K_CTRL_N},;
                     {xbeK_CTRL_O,           K_CTRL_O},;
                     {xbeK_CTRL_P,           K_CTRL_P},;
                     {xbeK_CTRL_Q,           K_CTRL_Q},;
                     {xbeK_CTRL_R,           K_CTRL_R},;
                     {xbeK_CTRL_S,           K_CTRL_S},;
                     {xbeK_CTRL_T,           K_CTRL_T},;
                     {xbeK_CTRL_U,           K_CTRL_U},;
                     {xbeK_CTRL_V,           K_CTRL_V},;
                     {xbeK_CTRL_W,           K_CTRL_W},;
                     {xbeK_CTRL_X,           K_CTRL_X},;
                     {xbeK_CTRL_Y,           K_CTRL_Y},;
                     {xbeK_CTRL_Z,           K_CTRL_Z},;
                     {xbeK_ALT_1,            K_ALT_1},;
                     {xbeK_ALT_2,            K_ALT_2},;
                     {xbeK_ALT_3,            K_ALT_3},;
                     {xbeK_ALT_4,            K_ALT_4},;
                     {xbeK_ALT_5,            K_ALT_5},;
                     {xbeK_ALT_6,            K_ALT_6},;
                     {xbeK_ALT_7,            K_ALT_7},;
                     {xbeK_ALT_8,            K_ALT_8},;
                     {xbeK_ALT_9,            K_ALT_9},;
                     {xbeK_ALT_0,            K_ALT_0}}
if nEvent      >= Asc(Space(01)) .and.;
   nEvent      <= 255
   nEventEquiv := nEvent
   lConverted  := .t.
else
   nFound := AScan(aGuiEvents, {|x| (nEvent == x[01])})
   if nFound       > 0
      nEventEquiv := aGuiEvents[nFound, 02]
      lConverted  := .t.
   else
      nEventEquiv := nEvent
      lConverted  := .f.
   endif
endif
RETURN lConverted
