int do_logical_MoveCloseBox(int xmv,int ymv, int idwindow)
{

if(window_focus_id==idwindow)
{
  if(mouse_y>ymv-15 && mouse_y<ymv+15 && mouse_y>hauteur_ChannelMenu)
  {
  if(mouse_x>xmv-15 && mouse_x<xmv+15)
  {
  if(mouse_button==1 && mouse_released==0 &&  im_moving_a_window==0 && original_posx==mouse_x && original_posy==mouse_y)
  {
  substract_a_window(idwindow);
  mouse_released=1;
  }
  }
  else if(((mouse_x>xmv+40-15 && mouse_x<xmv+40+15)|| im_moving_a_window==1)&& (original_posx==mouse_x && original_posy==mouse_y))
  {
  move_window(idwindow);
  }

  }
  }

 return(0);
}
////////////////////////////////////Fonctions clavier déplacées en fonction indépendantes pour mapping/////////////////////////
int key_switch_window_up()
{
//solo des fenetres
if (key_shifts & KB_CTRL_FLAG || index_false_control==1) //appel une par une

{
pos_focus_window=window_focus_id;
substract_a_window(pos_focus_window);
if(pos_focus_window<900){pos_focus_window=899;}
pos_focus_window++;
if(pos_focus_window>max_window_identity_is){pos_focus_window=900;}
add_a_window(pos_focus_window);
}

else//passage dune fenetre à l autre
{
index_to_navigate_between_window++;
nbre_fenetre_actives=check_nbre_opened_windows();
if(index_to_navigate_between_window>=nbre_fenetre_actives+1){index_to_navigate_between_window=0;}
if(window_opened[index_to_navigate_between_window]>0)
{
window_bring_to_front(window_opened[index_to_navigate_between_window]);
}
else {window_bring_to_front(window_opened[0]);   }
}
 return(0);
}
int key_unselect_ch()
{
reset_numeric_entry();

//if ((key_shifts & KB_SHIFT_FLAG  || index_false_shift==1))
if(key[KEY_LSHIFT]|| index_false_shift==1)
{
             if( index_patch_window==1 && index_ask_confirm==0)
             {
             patch_unselect_all_dimmers();
             strcpy(string_monitor_patch,"");
             index_patch_affect_is_done=0;
             }
}


else
{

             for (int ci=1;ci<514;ci++)
             {Selected_Channel[ci]=0;}
             last_ch_selected=0;
             index_type=0;index_level_attribue=0;
             substract_channel_selection_to_layers_plot();


             if(index_ask_confirm==1)
             {
             reset_indexs_confirmation();
             reset_index_actions();
             substract_a_window(W_ASKCONFIRM);
             window_focus_id=previous_window_focus_id;
             add_a_window(window_focus_id);
             }
}

return(0);
}
int commandes_clavier()//la fonction sprintf tue l acces clavier
{
if ( keypressed())
{

int chi = readkey(); 
scan_ascii_is=(chi & 0xff);//prend pas en compte touches fonctions
scan_allegro_key_is=(chi >> 8);//prend en compte tout le monde mais à redistribuer fr et anglais


switch (chi >> 8)  
{	
    

case KEY_ESC://nettoyage chaine de caractere et deselection totale

reset_indexs_confirmation();
reset_index_actions();
key_unselect_ch();
if(window_focus_id==W_PLOT )
{
if(index_menus_lighting_plot==1) unselect_all_shapes();
else if( index_menus_lighting_plot==2 || index_menus_lighting_plot==4)
{reset_symbols_selected(view_plot_calc_number_is);}
}
else if(window_focus_id==W_ASKCONFIRM)
{
 substract_a_window(W_ASKCONFIRM);
 substract_a_window(previous_window_focus_id);
 mouse_released=1;
 window_focus_id=previous_window_focus_id;
 add_a_window(window_focus_id);      
}
sprintf(string_key_id,list_keyname[9]);
break;

///////////////////////PAGE UP DOWN POUR FENETRES /////////////////////////////
case KEY_PGUP: 
sprintf(string_key_id,list_keyname[0]);
key_switch_window_up();
break; 
case KEY_PGDN: 
sprintf(string_key_id,list_keyname[0]);
key_switch_window_down();
break; 
//////////////////SPECIAL KEYS ////////////////////////////////////////////////
case  KEY_TILDE://carré
if(window_focus_id==W_PLOT) {index_move_plot_view_port=toggle(index_move_plot_view_port);}
break;

case KEY_F1://dock mode
if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
{
reset_indexs_confirmation();
index_ask_confirm=1; 
index_do_overrecord_mem=1;
clear_keybuf();

}
else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
{
int mem_to_rec=(int)(atof(numeric)*10);

reset_indexs_confirmation();
index_ask_confirm=1; 
index_do_create_mem=1;
}
else
{
index_do_report=0;
index_do_modify=0; 
index_main_clear=0;
index_do_dock=toggle(index_do_dock);

switch (window_focus_id)
{
case W_CHASERS:
index_affect_chaser_to_dock=index_do_dock;
break;   
case W_GRID:
for(int i=0;i<4;i++)
{
if(index_show_grid_player[i]==1)
{
gridplayer_to_affect_is=i; break;
}
}
break;
case W_MOVER:
index_affect_to_dock_mover=index_do_dock;     
break;    
case W_DRAW:
index_affect_draw_to_dock=index_do_dock;
break;
case W_ECHO:
index_affect_echo_to_dock=index_do_dock;
break;
case W_TIME:
index_affect_time=index_do_dock;   
break;
case W_TRACKINGVIDEO:
index_affect_video_tracking_to_dock=index_do_dock; 
break;
case W_TRICHROMY:
index_affect_color_to_dock=index_do_dock; 
break;
case W_AUDIO:
index_affect_audio_to_dock=index_do_dock;
player_to_affect_to_dock=0;
audio_type_for_dock_affectation_is=0;
break;
case W_CFGMENU:
if(config_page_is==1) { index_affect_dmxin=index_do_dock; }
else if(config_page_is==3) {index_do_affect_net_to_dock=index_do_dock; } 
break;
default:
break;      
}

}
break;
      
case KEY_F2:
index_do_dock=0;
index_do_report=0;
index_main_clear=0;
index_do_modify=toggle(index_do_modify);;      
break;      

case KEY_F3:
if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
{
index_do_dock=0;
index_do_modify=0; 
index_main_clear=0;
index_do_report=1;
reset_indexs_confirmation();
index_ask_confirm=1; 
index_do_overecord_mem_plus_faders=1;               
}     
else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) //creation mémoires en mode merge Faders / seq
{
index_do_dock=0;
index_do_modify=0; 
index_main_clear=0;
index_do_report=1;
int mem_to_rec=(int)(atof(numeric)*10);
reset_indexs_confirmation();
index_ask_confirm=1; 
index_do_create_mem_plus_faders=1;
}
else
{
index_do_dock=0;
index_do_modify=0; 
index_main_clear=0;
index_do_report=toggle(index_do_report); 
}
break;  

case KEY_F4:
index_do_dock=0;
index_do_modify=0; 
index_do_report=0;     
index_main_clear=toggle(index_main_clear);
break;  

case KEY_F5:
              index_type=toggle(index_type);
              sprintf(numeric,"");numeric_postext=0;
break; 

case KEY_F6:
         if(index_time==0){add_a_window(W_TIME);  } 
           else {   substract_a_window(W_TIME); }
break;  

case KEY_F7:
if(index_trichro_window==0){add_a_window(W_TRICHROMY);} 
else  { substract_a_window(W_TRICHROMY);  }
break;  

case KEY_F8:
  if(index_video_window==0){ add_a_window(W_TRACKINGVIDEO); } 
 else{ substract_a_window(W_TRACKINGVIDEO);}
break;  

case KEY_F9:
          if(index_window_sequentiel==0){;add_a_window(W_SEQUENCIEL);}
          else {substract_a_window(W_SEQUENCIEL);}
break;
case KEY_F10:
if (key_shifts & KB_SHIFT_FLAG  || index_false_shift==1) //CONFIG
{
if(index_show_minifaders==0){add_a_window(W_MINIFADERS);}
else {substract_a_window(W_MINIFADERS);}
}
else
{
if(index_show_faders==0){add_a_window(W_FADERS);}
else {substract_a_window(W_FADERS);}
}

break;  

case KEY_F11:
if (key_shifts & KB_SHIFT_FLAG  || index_false_shift==1) //CONFIG
{
if(index_show_config_window==0){add_a_window(W_CFGMENU);}
else {substract_a_window(W_CFGMENU);}     
}
else if (key_shifts & KB_CTRL_FLAG  || index_false_control==1 ) 
{index_blind=toggle(index_blind);   }
else
{
if(index_show_banger_window==0)
          {add_a_window(W_BANGER);mouse_level_for_event=mouse_z;mouse_level_for_banger=mouse_z;}
          else {substract_a_window(W_BANGER);}       
}
break;  
              
case KEY_F12://black out

if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
{
index_ask_confirm=1;index_do_quit_with_save=1;
}

else if (key_shifts & KB_SHIFT_FLAG   || index_false_shift==1) 
{
for (int i=0;i<12;i++)
{
specify_who_to_save_load[i]=0;}
reset_save_load_report_string();     
index_ask_confirm=1;index_do_quit_without_save=1;
}

else
{
if(index_blind==0)
{
for (int rs=0;rs<513;rs++)
{bufferSaisie[rs]=0;Selected_Channel[rs]=0;   }   
sprintf(string_Last_Order,">> Black Out done for On Stage channels");      
}     
else if(index_blind==1)
{
for (int rs=0;rs<513;rs++)
{bufferBlind[rs]=0; Selected_Channel[rs]=0;   }    
sprintf(string_Last_Order,">> Black Out done for On Blind channels");                       
}
             
substract_channel_selection_to_layers_plot();
}  
break;    


case KEY_UP:
key_up();
sprintf(string_key_id,list_keyname[1]);
break;

case KEY_DOWN:
key_down();
sprintf(string_key_id,list_keyname[2]);
break;

case KEY_ENTER :
key_affectation();
sprintf(string_key_id,list_keyname[3]);
break; 

case KEY_ENTER_PAD:
key_affectation();
sprintf(string_key_id,list_keyname[4]);
break; 

case KEY_EQUALS://+
key_add_ch();
sprintf(string_key_id,list_keyname[5]);
break;

case KEY_PLUS_PAD://+ num
key_add_ch();
sprintf(string_key_id,list_keyname[6]);
break;

case KEY_MINUS://-
key_minus_ch();
sprintf(string_key_id,list_keyname[7]);
break;

case KEY_MINUS_PAD://- num
key_minus_ch();
sprintf(string_key_id,list_keyname[8]);
break;


case KEY_TAB:
if(numeric_postext>0)
{
key_thruth();
sprintf(string_key_id,list_keyname[10]);
}
else 
{
if(window_focus_id==W_PLOT) {index_tab_on=toggle(index_tab_on); }  
}
break;
////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////TEXT TYPING OR FUNCTIONS CALLING//////////////////////////////////////////

case KEY_SPACE: 
              if (index_type==0)
             {
             key_go();
             }
              else if(index_type==1)
             {
             numeric[numeric_postext]=' ';
             numeric_postext++;
             }
       sprintf(string_key_id,list_keyname[11]);
       break;
             
         

        case KEY_Q: //lettre a
        if (key_shifts & KB_CTRL_FLAG  || index_false_control==1)
        {
        if(index_show_audio_window==0){add_a_window(W_AUDIO);}
        else {substract_a_window(W_AUDIO);}
        reset_audio_indexs_to_dock();       
        }
        else 
        {

             if(index_type==0)
             {
             key_presetvideo(0);
             }
             else  if (index_type==1)
             {
             numeric[numeric_postext]='A';
             numeric_postext++;
             }
         }
         sprintf(string_key_id,list_keyname[12]);
         break;  
       case KEY_B:
           if (index_type==0)
           {
           key_roi(10);
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='B';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[13]);
           break;
           
        case KEY_C:
            if (index_type==0)
           { 
            if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
            {
            if(numeric_postext==0)
            {
            channel_copy();
            }
            else
            {
            snap_mem_to_copy();  
            }
            } 
            else  if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
            {
            if(index_window_chasers==0){add_a_window(W_CHASERS);} 
            else {substract_a_window(W_CHASERS);}
            } 
           else
           {
           key_roi(8);         }
           } 
           else if (index_type==1)
           {
           numeric[numeric_postext]='C';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[14]);
           break;
           
        case KEY_D://dock mode on
           if(index_type==0)
           {
            key_roi(2);
           }
           else if(index_type==1)
           {
           numeric[numeric_postext]='D';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[15]);
           break;
           
        case KEY_E:
            if (index_type==0)
           {
           key_presetvideo(2);
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='E';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[16]);
           break;
           
        case KEY_F:
           if(index_type==0)
           {
           key_roi(3);
           }
           
           else if (index_type==1)
           {
           numeric[numeric_postext]='F';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[17]);
           break;
           
        case KEY_G:
            if (index_type==0)
           {
           if ((key_shifts & KB_CTRL_FLAG || index_false_control==1 ) && numeric_postext>0)
           {
           //GET CHANNELS FROM A MEMORY     
           int mem_to_take=(int)(atof(numeric)*10);
           if(MemoiresExistantes[mem_to_take]==1)
           {
           Get_channels_from_memory(mem_to_take);  
           }
           else {sprintf(string_Last_Order,"Get Sel. channel from %d.%d: mem doesn't exist",mem_to_take/10,mem_to_take%10);}   
           } 
           else {key_roi(4);}
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='G';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[18]);
           break;
           
           case KEY_H:

            if (index_type==0)
           {
           key_roi(5);   
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='H';
           numeric_postext++;
           }
           
           sprintf(string_key_id,list_keyname[19]);
           break;
        
        case KEY_I:    
           if(index_type==0) //full
           {
           key_full();
           }
           else if(index_type==1)
           {
           numeric[numeric_postext]='I';
           numeric_postext++;
           }
         sprintf(string_key_id,list_keyname[20]);
           break;
           
        case KEY_J:
           if (index_type==0)
           {
           key_time_out();
           }        
           if (index_type==1)
           {
           numeric[numeric_postext]='J';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[21]);
           break;
           
        case KEY_K:
            if (index_type==0)
           {
           key_time_in();
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='K';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[22]);
           break;
           
        case KEY_L://in + out
           if(index_type==0)
           {
           key_time_in_out();
           }
           else if(index_type==1)
           {
           numeric[numeric_postext]='L';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[23]);
           break;
        
        case KEY_SEMICOLON:
           if(index_type==0)//le M qui est point en clavier americain
           {
           if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
           { if(index_show_mover_window=0){add_a_window(W_MOVER);}
           else {substract_a_window(W_MOVER);}}
           }
           else if(index_type==1)
           {
           numeric[numeric_postext]='M';
           numeric_postext++;     
           }
           sprintf(string_key_id,list_keyname[38]);
           break;  
                
        case KEY_N:
           if (index_type==0)
           {
           key_roi(11);          
           } 
           else if (index_type==1)
           {
           numeric[numeric_postext]='N';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[24]);
           break;
           
        case KEY_O:
       
         
           if(index_type==0)
           { 
           key_at_zero();
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='O';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[25]);
           break;
           
        case KEY_P:

          if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
           {
           if(index_patch_window==0){add_a_window(W_PATCH);}
           else {substract_a_window(W_PATCH);} 
           } 
           else{
           if (index_type==0)
           {
             if(index_visual_pad==0){add_a_window(W_NUMPAD);}
             else {substract_a_window(W_NUMPAD);}  
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='P';
           numeric_postext++;
           }
           }
           sprintf(string_key_id,list_keyname[39]);
           break;

        case KEY_A: // lettre Q
            if (index_type==0)
           {
           key_roi(1);
            }
           else if (index_type==1)
           {
           numeric[numeric_postext]='Q';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[26]);
           break;        
  
        case KEY_R://report mode on
        if(index_type==0 )
        {
        key_presetvideo(3);;//les banques de tracking cam
        }
        else if(index_type==1)
        {
           numeric[numeric_postext]='R';
           numeric_postext++;
        }
        sprintf(string_key_id,list_keyname[27]);
           break;
           
        case KEY_S:
            if (index_type==0)
           {
           if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
           {
           if(index_is_saving==0){index_save_global_is=1;index_do_quick_save=1;}
           }
           else
           {
           key_roi(1);
           }
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='S';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[28]);
           break;
           
       case KEY_T:
           if(index_type==0)
           {
           key_presetvideo(4);//les banques de tracking cam
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='T';
           numeric_postext++;
           }         
           sprintf(string_key_id,list_keyname[29]);
           break;
           
        case KEY_U://inverse selection
           if (index_type==0)
           {
           key_select_inv();
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='U';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[30]);
           break;
           
        case KEY_V:
           if (index_type==0)
           {
           if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
           {
           if(numeric_postext==0)
            {
            channel_paste();
            }
            else//si chiffre de mem tapée
            {
            index_copy_mem_in=1; 
            index_ask_confirm=1;
            
            }              
           } 
           else
           {
           //les aires de tracking cam
           key_roi(9);
           }
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='V';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[31]);
           break;
           
        case KEY_Z://w
           if (index_type==0)
           {
           if(key_shifts )
           {
           key_backward();
           }
           else{//les aires de tracking cam
           key_roi(6);
           }        
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='W';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[32]);
           break;
           
        case KEY_X:
           if (index_type==0)
           {
           if(key_shifts)
           {
           key_forward();
           }
          
           else{//les aires de tracking cam
           key_roi(7);
           }
           }
           else  if (index_type==1)
           {
           numeric[numeric_postext]='X';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[33]);
           break;
           
        case KEY_Y://select all 
          
          if (index_type==0)
           {
          key_select_all();
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='Y';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[34]);
           break;
           
        case KEY_W://z
           if (key_shifts & KB_CTRL_FLAG  || index_false_control==1)
             {
             //ctrl Z reload mem as recorded
             index_do_reload_mem=1;
             index_ask_confirm=1;                   
             }
             else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1)
             {
             //ctrl Z resurrect mem as recorded
             mem_to_resurrect=(int)(atof(numeric)*10);   
             index_do_resurrect_mem=1;  
             index_ask_confirm=1;                            
             }
           else
           {
            if (index_type==0 )
           {
           key_presetvideo(1);//les banques de tracking cam
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='Z';
           numeric_postext++;
           }
           }
           sprintf(string_key_id,list_keyname[35]);
           break;
           
    case KEY_LEFT:
    key_left(); 
    sprintf(string_key_id,list_keyname[36]);
    break;
       
       case KEY_RIGHT:
       key_right();
       sprintf(string_key_id,list_keyname[37]);
       break;
      
      case KEY_DEL:
      if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
      {
      reset_indexs_confirmation(); 
      index_do_delete_mem=1;  
      index_ask_confirm=1;       
      }
      break;
//////////////////////ENTREES NUMERIQUES COMMUNES//////////////////////////////////////////

case KEY_0:
numeric[numeric_postext]='0';
numeric_postext++;
break;
case KEY_0_PAD:
numeric[numeric_postext]='0';
numeric_postext++;
break;
case KEY_1:
numeric[numeric_postext]='1';
numeric_postext++;
break;
case KEY_1_PAD:
numeric[numeric_postext]='1';
numeric_postext++;
break;

case KEY_2:
numeric[numeric_postext]='2';
numeric_postext++;
break;
case KEY_2_PAD:
numeric[numeric_postext]='2';
numeric_postext++;
break;
case KEY_3:
numeric[numeric_postext]='3';
numeric_postext++;
break;
case KEY_3_PAD:
numeric[numeric_postext]='3';
numeric_postext++;
break;
case KEY_4:
numeric[numeric_postext]='4';
numeric_postext++;
break;
case KEY_4_PAD:
numeric[numeric_postext]='4';
numeric_postext++;
break;
case KEY_5:
numeric[numeric_postext]='5';
numeric_postext++;
break;
case KEY_5_PAD:
numeric[numeric_postext]='5';
numeric_postext++;
break;
case KEY_6:
numeric[numeric_postext]='6';
numeric_postext++;
break;
case KEY_6_PAD:
numeric[numeric_postext]='6';
numeric_postext++;
break;
case KEY_7:
numeric[numeric_postext]='7';
numeric_postext++;
break;
case KEY_7_PAD:
numeric[numeric_postext]='7';
numeric_postext++;
break;
case KEY_8:
numeric[numeric_postext]='8';
numeric_postext++;
break;
case KEY_8_PAD:
numeric[numeric_postext]='8';
numeric_postext++;
break;
case KEY_9:
numeric[numeric_postext]='9';
numeric_postext++;
break;
case KEY_9_PAD:
numeric[numeric_postext]='9';
numeric_postext++;
break;   

case KEY_COMMA:
numeric[numeric_postext]='.';
numeric_postext++;
break;

case  KEY_DEL_PAD:
numeric[numeric_postext]='.';
numeric_postext++;
break;

case  KEY_M:
numeric[numeric_postext]='.';
numeric_postext++;
break;


case KEY_BACKSPACE:
numeric[numeric_postext]=' ';
numeric_postext--;
numeric[numeric_postext]=' ';
if (numeric_postext<0) {numeric_postext=0;}
break;   

////////////////////MISE EN MEMOIRES DES FENETRES ET TOGGLE/////////////////////
case KEY_PRTSCR:
key_printscreen();              
break; 

default:
      
break;
}  
for(int u=0;u<nbre_key_persos;u++)
{
//keys persos
if( (int)(chi & 0xff)==mapping_temporaire[u])
{
switch(u)
{
case 0://AT level
key_affectation();
sprintf(string_key_id,"At Level");//max 16 char
break;
case 1://CH+
key_add_ch();
sprintf(string_key_id,"Ch +");//max 16 char
break;
case 2://CH-
key_minus_ch();
sprintf(string_key_id,"Ch -");//max 16 char     
break;
case 3://CH THRUTH
key_thruth();
sprintf(string_key_id,"To Ch");//max 16 char     
break;
case 4://CLEAR
key_unselect_ch();
sprintf(string_key_id,"Clear");//max 16 char        
break;
default:
break;
}
}
}



   
//protections

if (numeric_postext>maxchar_numeric){numeric[numeric_postext]=' ';numeric_postext=maxchar_numeric-1;}

if (numeric_postext<0) {numeric_postext=0;} 


       
}
sprintf(string_numeric_entry,"<< %s",numeric);


//CTRL-S
if(index_do_quick_save==1 )
      {
      Save_Show();
      sprintf(string_Last_Order,">> Show Saved at %s", tmp_time);
      index_do_quick_save=0;
      }
      
poll_keyboard();
      
return(0);  
}
int key_affectation()
{
if ((key_shifts & KB_SHIFT_FLAG  || index_false_shift==1) && index_patch_window==1)
{
if(numeric_postext>0)//attribution directe
{
iddim=atoi(numeric);
if(iddim<513 && iddim!=0)
{
Dimmers_selected[iddim]=1;
}
last_dim_selected=iddim;
reset_numeric_entry();
numeric_postext=0;
}

for(int i=0;i<513;i++)
{
if(Dimmers_selected[i]==1)
{
Patch[i]=last_ch_selected;

if(index_build_patch_from_plot==1)
{
for (int l=0;l<4;l++)
{
for(int u=1;u<=nbre_symbols_on_plot[l];u++)
{
//reaffectations frappes clavier
if  ( symbol_is_selected[l][u] == 1 &&  symbol_channel_is[l][u] == last_ch_selected  )
     {symbol_dimmer_is[l][u]= iddim;}
}
}
}

}
}



generate_channel_view_list_from_patched_circuits();
if(index_patch_affect_is_done==1)//reset de ma string de control
{
strcpy(string_monitor_patch,"");
index_patch_affect_is_done=0;
}



char tmp_str_ch[4];
sprintf(tmp_str_ch,"%d",last_ch_selected);
strcat(string_monitor_patch," To Ch:");
strcat(string_monitor_patch,tmp_str_ch);
index_patch_affect_is_done=1;
patch_unselect_all_dimmers();
for (int ci=1;ci<514;ci++)
{Selected_Channel[ci]=0;}
last_ch_selected=0;
}
else if (key_shifts & KB_CTRL_FLAG || index_false_control==1)
{
sprintf(string_Last_Order,">> Setted Time");
read_time_string_entry();
}

else{
if(index_ask_confirm==0)
{
if(index_type==0)
{

//affectation d un niveau a la selection
bool detect_selectch_on=0;
for(int chk_ch=1;chk_ch<514;chk_ch++)
{
if (Selected_Channel[chk_ch]==1){detect_selectch_on=1;}
}
if(detect_selectch_on==1)
{
int chlevelis=0;
if(dmx_view==0)
{
if(atof(numeric)>0)
{
chlevelis=(int)((atof(numeric) *2.55) +1);// + 1 pour arrondir le pourcentage lors de la conversion % -> dmx
}
else {chlevelis=0;}
}
else if (dmx_view==1)
{chlevelis= atol(numeric);}

if(chlevelis>255){chlevelis=255;}
if(chlevelis<0){chlevelis=0;}

 for (int ci=1;ci<514;ci++)
 {
 switch(index_do_hipass)
 {
 case 0://normal
 if(Selected_Channel[ci]==1 && index_blind==0)    {bufferSaisie[ci]=chlevelis;}
 else if(Selected_Channel[ci]==1  && index_blind==1)    {bufferBlind[ci]=chlevelis;}
 break;
 case 1://mode hipass faders
 if(Selected_Channel[ci]==1)
 {
  FaderManipulating=highest_level_comes_from_fader[ci]-1;
  if(DockTypeIs[FaderManipulating][dock_used_by_fader_is[FaderManipulating]]==0)//pas les contenus dynamiques, juste les circuits enregistrés on the fly
  {
   FaderDockContains[FaderManipulating][dock_used_by_fader_is[FaderManipulating]][ci]  =chlevelis;
  }

}
break;
 }
 }
switch(dmx_view)
{
case 0:
sprintf(string_Last_Order,">> Selection AT %d",(int)(chlevelis/2.55));
break;
case 1:
sprintf(string_Last_Order,">> Selection AT %d", chlevelis);
break;
}
reset_numeric_entry();
index_level_attribue=1;
}
}
}
else if(index_ask_confirm==1)
{

  operations_confirmation();

  reset_index_actions();
  reset_indexs_confirmation();

  substract_a_window(W_ASKCONFIRM);
  window_focus_id=previous_window_focus_id;

}
}
 return(0);
}