rem: msg->Qualifier );
add: msg->Qualifier, &numlock );  if (numlock != amiga_numlock) { amiga_numlock = numlock; rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(read_keyboard_state()), 0); }
context: ui_select(int rdp_socket){  int n = rdp_socket;  fd_set rfds, wfds;  struct timeval tv;  Bool s_timeout = False;  static BOOL quit = FALSE;  while(TRUE)  {    int   res;    ULONG mask;    if (quit) {      if (amiga_clip_shutdown()) {	break;      }    }    FD_ZERO(&rfds);    FD_ZERO(&wfds);    FD_SET(rdp_socket, &rfds);    /* default timeout */    tv.tv_sec = 10;    tv.tv_usec = 0;    /* add redirection handles */    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);    n++;    mask = (1UL << amiga_wb_port->mp_SigBit) | amiga_clip_signals;#if defined(__libnix__) || defined(__amigaos4__)      mask |= SIGBREAKF_CTRL_C;#endif    if( amiga_window != NULL )    {      mask |= ( 1UL << amiga_window->UserPort->mp_SigBit );    }    #ifdef WITH_RDPSND    if( amiga_audio_signal != -1 )    {      mask |= ( 1UL << amiga_audio_signal );    }#endif#ifdef __amigaos4__    res  = WaitSelect(n, &rfds, &wfds, NULL, &tv, &mask );#else# ifdef __libnix__    res  = lx_select(n, &rfds, &wfds, NULL, &tv, &mask );# else    res  = ix_select(n, &rfds, &wfds, NULL, &tv, &mask );# endif#endif    if( res == -1 && mask == 0 )    {      error("select: %s\n", strerror(errno));      return False;    }#if defined(__libnix__) || defined(__amigaos4__)    if (mask & SIGBREAKF_CTRL_C) {      SetSignal(0,SIGBREAKF_CTRL_C);      quit = TRUE;    }#endif    if (mask & (amiga_clip_signals)) {      amiga_clip_handle_signals();    }          if( mask & ( 1UL << amiga_wb_port->mp_SigBit ) )      {	struct AppMessage* msg;	while( ( msg = (struct AppMessage*) 		 GetMsg( amiga_wb_port ) ) != NULL )	{	  if( msg->am_NumArgs == 0 )	  {	    if( amiga_app_icon != NULL )	    {	      RemoveAppIcon( amiga_app_icon );	      amiga_app_icon = NULL;#ifdef __MORPHOS__	      ShowWindow( amiga_window );#endif#ifdef __amigaos4__	      ShowWindow( amiga_window, WINDOW_FRONTMOST );	      ActivateWindow( amiga_window );#endif	    }	  }	  ReplyMsg( (struct Message*) msg );	}      }#ifdef WITH_RDPSND      if( amiga_audio_signal != -1 &&	  ( mask & ( 1UL << amiga_audio_signal ) ) )      {	wave_out_play();      }#endif       if( amiga_window != NULL &&	  ( mask & ( 1UL << amiga_window->UserPort->mp_SigBit ) ) )      {	struct IntuiMessage* msg;	struct InputEvent ie;	char   q_buffer[8];	ie.ie_Class = IECLASS_RAWKEY;	ie.ie_SubClass = 0;	while( ( msg = (struct IntuiMessage*) 		 GetMsg( amiga_window->UserPort ) ) != NULL )	{	  uint32 ev_time;	  ev_time = time(NULL);	  amiga_last_qualifier = msg->Qualifier;	  switch( msg->Class )	  {	    case IDCMP_CLOSEWINDOW:	      quit = TRUE;	      break;            case IDCMP_ACTIVEWINDOW:              // Make sure the cursor colors are correct//              GetRGB32( amiga_window->WScreen->ViewPort.ColorMap,//                        16 + 1, 3, amiga_cursor_colors );              SetRGB32( &amiga_window->WScreen->ViewPort, 16 + 1,                        0x00000000, 0x00000000, 0x00000000 );              SetRGB32( &amiga_window->WScreen->ViewPort, 16 + 3,                        0xffffffff, 0xffffffff, 0xffffffff );	      if( amiga_last_cursor != NULL )	      {		ui_set_cursor( amiga_last_cursor );	      }	                    break;            case IDCMP_INACTIVEWINDOW:              // Restore cursor colors              SetRGB32( &amiga_window->WScreen->ViewPort, 16 + 1,                        amiga_cursor_colors[ 0 ],                        amiga_cursor_colors[ 1 ],                        amiga_cursor_colors[ 2 ] );              SetRGB32( &amiga_window->WScreen->ViewPort, 16 + 3,                        amiga_cursor_colors[ 6 ],                        amiga_cursor_colors[ 7 ],                        amiga_cursor_colors[ 8 ] );	      ui_set_null_cursor();              break;            case IDCMP_NEWSIZE:              if( ( amiga_window->Flags & WFLG_ZOOMED ) == 0 )              {		amiga_restore_window();              }              break;            case IDCMP_SIZEVERIFY:              if( ( amiga_window->Flags & WFLG_ZOOMED ) == 0 )              {		amiga_backup_window();              }              break;	    case IDCMP_GADGETUP:	    {	      struct Gadget* g = (struct Gadget*) msg->IAddress;#if defined(__MORPHOS__) || defined(__amigaos4__)	      if( g->GadgetID == ETI_Iconify &&		  amiga_app_icon == NULL )	      {		amiga_icon->do_Type = 0;		amiga_app_icon = AddAppIconA( 0, 0, g_title,					      amiga_wb_port, NULL, amiga_icon, NULL );		if( amiga_app_icon != NULL )		{		  HideWindow( amiga_window );		}	      }#endif		  	      break;	    }            	    case IDCMP_RAWKEY:	    {	      int scancode;	      int flag;#if defined(HAVE_NEWMOUSE_H) || defined(HAVE_DEVICES_NEWMOUSE_H)	      int button = 0;	      switch (msg->Code & ~0x80) {#if defined(HAVE_DEVICES_RAWKEYCODES_H)		case RAWKEY_NM_WHEEL_UP:#elif defined(HAVE_NEWMOUSE_H)		case NM_WHEEL_UP:#endif		  button = MOUSE_FLAG_BUTTON4 | MOUSE_FLAG_DOWN;		  break;#if defined(HAVE_DEVICES_RAWKEYCODES_H)		case RAWKEY_NM_WHEEL_DOWN:#elif defined(HAVE_NEWMOUSE_H)		case NM_WHEEL_DOWN:#endif		  button = MOUSE_FLAG_BUTTON5 | MOUSE_FLAG_DOWN;		  break;	      }	      if (button != 0) {		rdp_send_input( ev_time, RDP_INPUT_MOUSE,				button,                                msg->MouseX - amiga_window->BorderLeft,                                msg->MouseY - amiga_window->BorderTop );		break;	      }#endif	      //printf("code %d %x, qualifier %x\n", msg->Code, msg->Code, msg->Qualifier);	      // RAmiga-Q quits.	      ie.ie_Code = msg->Code;	      ie.ie_Qualifier = msg->Qualifier;	      /* recover dead key codes & qualifiers */	      ie.ie_EventAddress = (APTR*) *((ULONG*) msg->IAddress);	      q_buffer[0] = 0;	      if( MapRawKey(&ie, q_buffer, sizeof (q_buffer), NULL) == 1 &&		  q_buffer[0] == 'q' &&		  (msg->Qualifier & (IEQUALIFIER_LSHIFT |				     IEQUALIFIER_RSHIFT |				     IEQUALIFIER_CAPSLOCK |				     IEQUALIFIER_CONTROL |				     IEQUALIFIER_LALT |				     IEQUALIFIER_RALT |				     IEQUALIFIER_LCOMMAND |				     IEQUALIFIER_RCOMMAND |				     IEQUALIFIER_NUMERICPAD))		  == IEQUALIFIER_RCOMMAND) {		quit = TRUE;		break;	      }	                    if( msg->Code & 0x80 )              {                flag = KBD_FLAG_UP;              }              else              {                flag = KBD_FLAG_DOWN;              }	      scancode = amiga_translate_key( msg->Code & ~0x80,					      msg->Qualifier );              if( scancode == 0 )                break;                              if( scancode == 0x3a )              {                // Handle CAPS LOCK                		rdp_send_input( ev_time, RDP_INPUT_SCANCODE, 0,				0x3a, 0);                flag = KBD_FLAG_UP;              }              if( scancode & 0x80 )              {                flag     |= KBD_FLAG_EXT;                scancode &= ~0x80;              }	      rdp_send_input( ev_time, RDP_INPUT_SCANCODE, flag,			      scancode, 0);	      break;	    }	    case IDCMP_MOUSEBUTTONS:	    {	      int button = 0;    	        	      switch( msg->Code )	      {		case SELECTDOWN:		  button = MOUSE_FLAG_BUTTON1 | MOUSE_FLAG_DOWN;		  break;		case MENUDOWN:		  button = MOUSE_FLAG_BUTTON2 | MOUSE_FLAG_DOWN;		  break;		case MIDDLEDOWN:		  button = MOUSE_FLAG_BUTTON3 | MOUSE_FLAG_DOWN;		  break;		case SELECTUP:		  button = MOUSE_FLAG_BUTTON1;		  break;		case MENUUP:		  button = MOUSE_FLAG_BUTTON2;		  break;		case MIDDLEUP:		  button = MOUSE_FLAG_BUTTON3;		  break;    	                            default:                  error( "ui_select: Unknown button code: %d\n", msg->Code );                  break;	      }              if( button != 0 )              {		rdp_send_input( ev_time, RDP_INPUT_MOUSE,				button,                                msg->MouseX - amiga_window->BorderLeft,                                msg->MouseY - amiga_window->BorderTop );              }	      break;	    }	          	    case IDCMP_MOUSEMOVE:	    {              rdp_send_input( ev_time, RDP_INPUT_MOUSE,			      MOUSE_FLAG_MOVE,                              msg->MouseX - amiga_window->BorderLeft,                              msg->MouseY - amiga_window->BorderTop );	      break;            }	    default:	      error( "Unexpected IDCMP: %d\n", (int) msg->Class );	      break;          }	  ReplyMsg( (struct Message*) msg );	}      }    if( res > 0 )    {      rdpdr_check_fds(&rfds, &wfds, (Bool) False);      if (FD_ISSET(rdp_socket, &rfds))      {	return True;      }    }  }	  return False;}