done_principal = false
debut_multi_win1 = 1
debut_multi_win2 = 1
multi_win_nb = 1
i_defilement_horizontal_win1 = 0
i_defilement_horizontal_win2 = 0
multi_win_lignes1 = {}
multi_win_lignes2 = {}
multi_win_nom1 = "defaut.lua"
multi_win_nom2 = "defaut.lua"
multi_win_dir1 = System.currentDirectory()
multi_win_dir2 = System.currentDirectory()
clavier_x = 323
a=1
enregistrer = false
statut_menu = "no"
oldpad = Controls.read()
xligne = 1
x = 0
y = 0
aff_clavier = false
type_clavier = 1
type_clavier2 = 0
clavierir = 0
cara = 0
aff_couleur = true
i_defilement_horizontal = 0
tre = ""
lignes={}
lignes_a_ouvrir={}
name = "defaut.lua"
sel1_h_win1,sel1_l_win1,sel2_h_win1,sel2_l_win1 = 0,0,0,0
sel1_h_win2,sel1_l_win2,sel2_h_win2,sel2_l_win2 = 0,0,0,0
txt_fichier=name
repertoire=System.currentDirectory()
repertoire_path=System.currentDirectory()

file = io.open(name)
n = 0
for line in file:lines() do
    n = n + 1
end
file:close()
file = io.open(name)
p = 1
for line in file:lines() do
    lignes_a_ouvrir[p] = line
    p = p + 1
end
file:close()
-- Lecture du fichier
p = table.getn(lignes)
for i = 1, p do
   table.remove(lignes, i)
   table.remove(multi_win_lignes1, i)
   table.remove(multi_win_lignes2, i)
end
for i=1, n do
    table.insert(multi_win_lignes1, i, lignes_a_ouvrir[i])
    table.insert(multi_win_lignes2, i, lignes_a_ouvrir[i])
    table.insert(lignes, i, lignes_a_ouvrir[i])
end
 
for i=1, n do
   verifie_signe_bizarre = string.sub(lignes[i],string.len(lignes[i]))
   if verifie_signe_bizarre == "\r" then
	 lignes[i] = string.sub(lignes[i],0,string.len(lignes[i]) - 1)
	 multi_win_lignes1[i] = string.sub(multi_win_lignes1[i],0,string.len(multi_win_lignes1[i]) - 1)
	 multi_win_lignes2[i] = string.sub(multi_win_lignes2[i],0,string.len(multi_win_lignes2[i]) - 1)
   end
end
 
n_lignes_win1 = n
n_lignes_win2 = n
done_aide_test = false
done_aide_gotest = false
test_espace = 0
test_end = 0
xcurseur = 0
ycurseur = 49
debut = 1
lignes_a_ouvrir={}
lignes_a_ouvrir[1]="r"
aide_principal = false
lect = 0
nb_search_win1 = 1
nb_search_win2 = 1
tmp_l={}
word_search = "LuaProg"

dofile("data/data.lua")

function option_fn()
   dofile("data/data.lua")
   selec=1
   img = Image.load("images/option.png")
   while true do
	 screen:clear()
	 screen:blit(0,0,img)
	 pad=Controls.read()
	 if pad:start() and not oldpad:start() then
	    oldpad=pad
	    file = io.open("data/data.lua","w")
	    file:write("-- Merci de ne pas editer \n\n")
	    file:write("autosave_etat = "..autosave_etat.."\n")
	    if couleur_etat == 1 then
		  file:write("couleur_select = Color.new(0,0,0) \n")
	    elseif couleur_etat == 2 then
		  file:write("couleur_select = Color.new(0,0,255) \n")
		  elseif couleur_etat == 3 then
		  file:write("couleur_select = Color.new(255,0,0) \n")
	    end
	    file:write("couleur_etat = "..couleur_etat.."\n")
	    file:close()
	    break
	 end
	 if pad:circle() and not oldpad:circle() then
	    oldpad=pad
	    break
	 end
	 if pad:up() and not oldpad:up() then
	    if selec == 1 then
		  selec = 2
	    else
		  selec = 1
	    end
	 elseif pad:down() and not oldpad:down() then
	    if selec == 1 then
		  selec = 2
	    else
		  selec = 1
	    end
	 end
	 if selec==1 then
	    if pad:left() and not oldpad:left() then
		  if autosave_etat == 1 then
			autosave_etat = 2
		  else
			autosave_etat = 1
		  end
	    elseif pad:right() and not oldpad:right() then
		  if autosave_etat == 1 then
			autosave_etat = 2
		  else
			autosave_etat = 1
		  end
	    end
	    if autosave_etat == 1 then
		  screen:print(120,31,"ON",jaune)
	    else
		  screen:print(120,31,"OFF",jaune)
	    end
	    if couleur_etat == 1 then
		  screen:print(140,51,"Noir",blanc)
	    elseif couleur_etat == 2 then
		  screen:print(140,51,"Bleu",blanc)
	    elseif couleur_etat == 3 then
		  screen:print(140,51,"Rouge",blanc)
	    end
	 elseif selec==2 then
	    if pad:left() and not oldpad:left() then
		  if couleur_etat == 1 then
			couleur_etat = 3
		  elseif couleur_etat == 2 then
			couleur_etat = 1
		  elseif couleur_etat == 3  then
			couleur_etat = 2
		  end
	    elseif pad:right() and not oldpad:right() then
		  if couleur_etat == 1 then
			couleur_etat = 2
		  elseif couleur_etat == 2 then
			couleur_etat = 3
		  elseif couleur_etat == 3  then
			couleur_etat = 1
		  end
	    end
	    if autosave_etat == 1 then
		  screen:print(120,31,"ON",blanc)
	    else
		  screen:print(120,31,"OFF",blanc)
	    end
	    if couleur_etat == 1 then
		  screen:print(140,51,"Noir",jaune)
	    elseif couleur_etat == 2 then
		  screen:print(140,51,"Bleu",jaune)
	    elseif couleur_etat == 3 then
		  screen:print(140,51,"Rouge",jaune)
	    end
	 end
	 screen.flip()
	 screen.waitVblankStart()
	 oldpad=pad
   end
   img = nil
   System.memclean()
   dofile("data/data.lua")
   curseur:clear(couleur_select)
end

function find_char_win1(str_find, next)
   for i=next, n_lignes_win1 do
	 if string.find(multi_win_lignes1[i], str_find) ~= nil then
	    nb_search_win1=i+1
	    debut_multi_win1=i
	    return 1
	 end
   end
end

function find_char_win2(str_find, next)
   for i=next, n_lignes_win2 do
	 if string.find(multi_win_lignes2[i], str_find) ~= nil then
	    nb_search_win2=i+1
	    debut_multi_win2=i
	    return 1
	 end
   end
end
 
function find_gui()
   mot=word_search
   fond=Image.load("images/search.png")
   while true do
	 screen:clear(blanc)
	 pad=Controls.read()
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    mot = System.startOSK(mot, "Mot recherche")
	 end
	 if pad:circle() and oldpad:circle() ~= pad:circle() then
	    fond = nil
	    System.memclean()
	    oldpad=pad
	    return
	 end
	 if pad:start() and mot ~="" then	 
	    oldpad=pad
	    if mot ~= word_search then
		  if multi_win_nb == 1 then
			nb_search_win1 = 1
		  else
			nb_search_win2 = 1
		  end
	    end
	    if multi_win_nb == 1 then
		  find_char_win1(mot,nb_search_win1)
	    else
		  find_char_win2(mot,nb_search_win2)
	    end
	    word_search = mot
	    fond = nil
	    System.memclean()
	    return
	 end
	 screen:blit(0,0,fond)
	 screen:print(150,130,mot,blanc)
	 screen.flip()
	 screen.waitVblankStart()
	 oldpad=pad
   end
end
 
function remplace_win1(str_find, str_new)
   for i=1, n_lignes_win1 do
	 multi_win_lignes1[i] = string.gsub(multi_win_lignes1[i], str_find, str_new)
   end
end

function remplace_win2(str_find, str_new)
   for i=1, n_lignes_win2 do
	 multi_win_lignes2[i] = string.gsub(multi_win_lignes2[i], str_find, str_new)
   end
end

function replace_gui()
   new="Lua"
   old="Prog"
   fond=Image.load("images/remplace.png")
   sel=1
   while true do
	 screen:clear(blanc)
	 pad=Controls.read()   
	 if pad:circle() then 
	    oldpad=pad
	    return
	 end
	 if pad:up() then sel=1 end
	 if pad:down() then sel=2 end
	 screen:blit(0,0,fond)
	 screen:print(180,100,old,blanc)
	 screen:print(180,170,new,blanc)
	 if sel==1 then
	    screen:print(180,100,old,jaune)
	    if pad:cross() and oldpad:cross() ~= pad:cross() then
			 old = System.startOSK(old,"Ancien mot")
	    end
	 elseif sel==2 then
	    screen:print(180,170,new,jaune)
	    if pad:cross() then
			 new = System.startOSK(new, "Nouveau mot")
	    end
	 end
	 if pad:start() and old ~="" and new ~= "" then	 
	    oldpad=pad
	    if autosave_etat == 1 then
		  if multi_win_nb == 1 then
			autosave_win1("tmp/replace1.lua")
		  else
			autosave_win2("tmp/replace2.lua")
		  end
		  System.currentDirectory(repertoire)
	    end
	    if multi_win_nb == 1 then
		  remplace_win1(old, new)
	    else
		  remplace_win2(old, new)
	    end
	    fond = nil
	    System.memclean()
	    return
	 end
	 screen.flip()
	 screen.waitVblankStart()
	 oldpad=pad
   end
end
 
function mp3()
   while true do
	 screen:clear()
 
	 if n_mp3 == 0 then break end 
 
	 screen:print(70,39,nommp3[selecteur].name,blanc)
	 screen:print(10,(180),"X",Color.new(0,0,255))
	 screen:print(30,(180),"X",Color.new(0,30,255))
	 screen:print(50,(180),"X",Color.new(0,60,255))
	 screen:print(70,(180),"X",Color.new(0,90,255))
	 screen:print(90,(180),"X",Color.new(0,120,255))
	 screen:print(110,(180),"X",Color.new(0,150,255))
	 screen:print(130,(180),"X",Color.new(0,170,255))
	 screen:print(150,(180),"X",Color.new(0,200,255))
	 screen:print(170,(180),"X",Color.new(0,230,255))
	 screen:print(190,(180),"X",Color.new(0,255,255))
	 screen:print(210,(180),"X",Color.new(30,255,255))
	 screen:print(230,(180),"X",Color.new(60,255,255))
	 screen:print(250,(180),"X",Color.new(90,255,255))
	 screen:print(270,(180),"X",Color.new(120,255,255))
	 screen:print(290,(180),"X",Color.new(150,255,255))
	 screen:print(310,(180),"X",Color.new(170,255,255))
	 screen:print(330,(180),"X",Color.new(200,255,255))
	 screen:print(350,(180),"X",Color.new(230,255,255))
	 screen:print(370,(180),"X",Color.new(245,255,255))
	 screen:print(390,(180),"X",Color.new(255,255,255))
	 screen:print(370,59,"0%",blanc)
	 screen:print(300,69,"00:00:00 / 00:00:00",blanc)
 
	 if selecteur-1>=1 then
	    screen:print(70,29,nommp3[selecteur-1].name,rouge)
	 end
 
	 if selecteur+1<=selectmax then
	    screen:print(70,49,nommp3[selecteur+1].name,rouge)
	 end
 
	 pad = Controls.read()
 
	 if pad:down() then 
	    if selecteur ~= selectmax  then 
		  selecteur = selecteur + 1
	    end 
	 end 
 
	 if pad:up() then 
	    if selecteur ~= 1  then 
		  selecteur = selecteur - 1
	    end 
	 end
 
	 if pad:r() and pad:l() then 
	    clavierir = 0 
	    aff_couleurs = false 
	    return
	 end
 
	 if pad:cross() or lect == 1 then  
	    if lect == 0  then
		  System.currentDirectory("ms0:/PSP/MUSIC/")
		  if lect==1 then Mp3me.stop() System.memclean() end
		  Mp3me.load (nommp3[selecteur].name)
		  Mp3me.play()
		  System.currentDirectory(dirst)
		  lect=1
	    end
	    while true do
			screen:clear()
			screen:print(70,39,nommp3[selecteur].name,blanc)
			pourc = Mp3me.percent()
			time = Mp3me.gettime()
			songtime = Mp3me.songTime()
			vis = Mp3me.vis(5)
			vis1 = Mp3me.vis(10)
			vis2 = Mp3me.vis(15)
			vis3 = Mp3me.vis(20)
			vis4 = Mp3me.vis(25)
			vis5 = Mp3me.vis(30)
			vis6 = Mp3me.vis(35)
			vis7 = Mp3me.vis(40)
			vis8 = Mp3me.vis(45)
			vis9 = Mp3me.vis(50)
			vis10 = Mp3me.vis(55)
			vis11 = Mp3me.vis(60)
			vis12 = Mp3me.vis(65)
			vis13 = Mp3me.vis(70)
			vis14 = Mp3me.vis(75)
			vis15 = Mp3me.vis(80)
			vis16 = Mp3me.vis(85)
			vis17 = Mp3me.vis(90)
			vis18 = Mp3me.vis(95)
			vis19 = Mp3me.vis(100)
			screen:print(10,(270-vis),"X",Color.new(0,0,255))
			screen:print(30,(270-vis1),"X",Color.new(0,30,255))
			screen:print(50,(270-vis2),"X",Color.new(0,60,255))
			screen:print(70,(270-vis3),"X",Color.new(0,90,255))
			screen:print(90,(270-vis4),"X",Color.new(0,120,255))
			screen:print(110,(270-vis5),"X",Color.new(0,150,255))
			screen:print(130,(270-vis6),"X",Color.new(0,170,255))
			screen:print(150,(270-vis7),"X",Color.new(0,200,255))
			screen:print(170,(270-vis8),"X",Color.new(0,230,255))
			screen:print(190,(270-vis9),"X",Color.new(0,255,255))
			screen:print(210,(270-vis10),"X",Color.new(30,255,255))
			screen:print(230,(270-vis11),"X",Color.new(60,255,255))
			screen:print(250,(270-vis12),"X",Color.new(90,255,255))
			screen:print(270,(270-vis13),"X",Color.new(120,255,255))
			screen:print(290,(270-vis14),"X",Color.new(150,255,255))
			screen:print(310,(270-vis15),"X",Color.new(170,255,255))
			screen:print(330,(270-vis16),"X",Color.new(200,255,255))
			screen:print(350,(270-vis17),"X",Color.new(230,255,255))
			screen:print(370,(270-vis18),"X",Color.new(245,255,255))
			screen:print(390,(270-vis19),"X",Color.new(255,255,255))
			screen:print(370,59,pourc.."%",blanc)
			screen:print(300,69,time.." / "..songtime,blanc)
			pad = Controls.read()
			if pad:cross() then
			   Mp3me.pause() 
			end 
			if pad:circle() then 
			   Mp3me.stop()
			   lect=0
			   break
			end 
			if pad:r() and pad:l() then return end
			screen:flip()
		  end 
	    screen:flip()
	 end 
	 screen:flip()
	 screen.waitVblankStart(10) 
   end 
end

function autosave_win1(path_autosave)
 
   System.currentDirectory(repertoire_path)
   if i_defilement_horizontal_win1 == 4 then
		i_defilement_horizontal_win1 = i_defilement_horizontal_win1-1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		for id=1, n_lignes_defilement do
			multi_win_lignes1[id] = multi_win1_sauv_ligne3[id]..multi_win_lignes1[id]
		end
   end
   if i_defilement_horizontal_win1 == 3 then
		i_defilement_horizontal_win1 = i_defilement_horizontal_win1-1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		for id=1, n_lignes_defilement do
			multi_win_lignes1[id] = multi_win1_sauv_ligne2[id]..multi_win_lignes1[id]
		end
   end
   if i_defilement_horizontal_win1 == 2 then
		i_defilement_horizontal_win1 = i_defilement_horizontal_win1-1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		for id=1, n_lignes_defilement do
			multi_win_lignes1[id] = multi_win1_sauv_ligne1[id]..multi_win_lignes1[id]
		end
   end
   if i_defilement_horizontal_win1 == 1 then
		i_defilement_horizontal_win1 = i_defilement_horizontal_win1 - 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		for id=1, n_lignes_defilement do
			multi_win_lignes1[id] = multi_win1_sauv_ligne[id]..multi_win_lignes1[id]
		end
   end
   file = io.open(path_autosave,"w")
   n = table.getn(lignes)
   if n > 0 then
	 for i=1, n do
	    System.sleep(5)
	    file:write(lignes[i].."\n")
	 end
   else
	 file:write("nil")
   end
	 file:close()
 
end
 
function autosave_win2(path_autosave)
 
   System.currentDirectory(repertoire_path)
   if i_defilement_horizontal_win2 == 4 then
		i_defilement_horizontal_win2 = i_defilement_horizontal_win2-1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		for id=1, n_lignes_defilement do
			multi_win_lignes2[id] = multi_win2_sauv_ligne3[id]..multi_win_lignes2[id]
		end
   end
   if i_defilement_horizontal_win2 == 3 then
		i_defilement_horizontal_win2 = i_defilement_horizontal_win2-1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		for id=1, n_lignes_defilement do
			multi_win_lignes2[id] = multi_win2_sauv_ligne2[id]..multi_win_lignes2[id]
		end
   end
   if i_defilement_horizontal_win2 == 2 then
		i_defilement_horizontal_win2 = i_defilement_horizontal_win2-1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		for id=1, n_lignes_defilement do
			multi_win_lignes2[id] = multi_win2_sauv_ligne1[id]..multi_win_lignes2[id]
		end
   end
   if i_defilement_horizontal_win2 == 1 then
		i_defilement_horizontal_win2 = i_defilement_horizontal_win2 - 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		for id=1, n_lignes_defilement do
			multi_win_lignes2[id] = multi_win2_sauv_ligne[id]..multi_win_lignes2[id]
		end
   end
   file = io.open(path_autosave,"w")
   n = table.getn(lignes)
   if n > 0 then
	 for i=1, n do
	    System.sleep(5)
	    file:write(lignes[i].."\n")
	 end
   else
	 file:write("nil")
   end
	 file:close()
 
end

function menu()
	--textes
	if pad:l() and oldpad:l() ~= pad:l() and statut_menu == "no" and aff_clavier == false then
		statut_menu = "fichier"
	elseif pad:l() and oldpad:l() ~= pad:l() and statut_menu ~= "no" and aff_clavier == false then
		statut_menu = "no"
	end
 
   if pad:triangle() then
	 statut_menu = "no"
   end

   if statut_menu == "fichier" then
	 screen:blit(0,26,principal,10,276,144,65)
	 screen:blit(0,26,principal,160,276,139,20)
	 screen:blit(0,3,principal,290,313,50,20)
	 if pad:down() and oldpad:down() ~= pad:down() then statut_menu = "enregistrer" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "affichage" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    curseur = nil
	    curseur = Image.createEmpty(1,32)
	    curseur:clear(couleur_select)
	    dofile("ouvrir.lua")
	    if ouvrir == true then
		  curseur = Image.createEmpty(1,32)
		  curseur:clear(couleur_select)
		  xcurseur = 0
		  ycurseur = 49
		  if multi_win_nb == 1 then
			p = table.getn(multi_win_lignes1)
			for i = 1, p do
			   table.remove(multi_win_lignes1, i)
			end
			for i=1, n do
			   table.insert(multi_win_lignes1, i, lignes_a_ouvrir[i])
			end
			multi_win_nom1 = name
			multi_win_dir1 = dossier_en_cours
			n_lignes_win1 = n
			debut_multi_win1 = 1
			i_defilement_horizontal_win1 = 0
			remplace_win1("\t", "	")
			remplace_win1("é", "e")
			remplace_win1("à", "a")
			remplace_win1("è", "e")
			remplace_win1("ê", "e")
		  else
			p = table.getn(multi_win_lignes2)
			for i = 1, p do
			   table.remove(multi_win_lignes2, i)
			end
			for i=1, n do
			   table.insert(multi_win_lignes2, i, lignes_a_ouvrir[i])
			end
			multi_win_nom2 = name
			multi_win_dir2 = dossier_en_cours
			n_lignes_win2 = n
			i_defilement_horizontal_win2 = 0
			debut_multi_win2 = 1
			remplace_win2("\t", "	")
			remplace_win2("é", "e")
			remplace_win2("à", "a")
			remplace_win2("è", "e")
			remplace_win2("ê", "e")
		  end
	    end
	 end
	 oldpad = pad
   end
   if statut_menu == "quitter" then
	 screen:blit(0,26,principal,10,276,144,65)
	 screen:blit(0,66,principal,160,276,139,20)
	 screen:blit(0,3,principal,290,313,50,20)
	 if pad:up() and oldpad:up() ~= pad:up() then statut_menu = "enregistrer" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "affichage" end
	 if pad:cross() then System.Quit() end
	 oldpad = pad
   end
   if statut_menu == "enregistrer" then
	 screen:blit(0,26,principal,10,276,144,65)
	 screen:blit(0,46,principal,160,276,139,20)
	 screen:blit(0,3,principal,290,313,50,20)
	 if pad:up() and oldpad:up() ~= pad:up() then statut_menu = "fichier" end
	 if pad:down() and oldpad:down() ~= pad:down() then statut_menu = "quitter" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "affichage" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    dofile("enregistrer.lua")
	    oldpad = pad
	 end
	 oldpad = pad
   end
   if statut_menu == "affichage" then
	 screen:blit(46,26,principal,6,346,147,24)
	 screen:blit(50,26,principal,160,346,139,20)
	 screen:blit(50,3,principal,340,313,65,20)
	 if aff_couleurs == true then
	    screen:blit(178,32,principal,158,372,7,8)
	 else
	    screen:blit(177,31,principal,167,371,10,10)
	 end
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "fichier" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "tester" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    if aff_couleurs == true then
		  aff_couleurs = false
	    else
		  aff_couleurs = true
	    end
	    statut_menu = "no"
	 end
	 oldpad = pad
   end
   if statut_menu == "tester" then
	 screen:blit(115,3,principal,405,313,49,20)
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "affichage" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "?" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
		oldpad=pad
	    while done_aide_gotest == false do
	    pad = Controls.read()
	    screen:clear()
	    screen:blit(0,0,aide_test_go)
	    if pad:cross() and oldpad:cross() ~= pad:cross() then done_aide_gotest = true end
	    if pad:start() and oldpad:start() ~= pad:start() then done_aide_gotest = true
		  if autosave_etat == 1 then
			if multi_win_nb == 1 then
			   autosave_win1("tmp/test1.lua")
			else
			   autosave_win2("tmp/test2.lua")
			end
			System.currentDirectory(repertoire)
		  end
		  if multi_win_nb == 1 then
			dofile(multi_win_nom1)
		  else
			dofile(multi_win_nom2)
		  end
		  statut_menu = "no"
	    end
	   screen.waitVblankStart()
	   screen.flip()
		oldpad=pad
	    end
	    done_aide_gotest = false
	 end
	 oldpad = pad
   end
 
 
   if statut_menu == "?" then
	 screen:blit(160,26,principal,306,276,147,24)
	 screen:blit(164,26,principal,160,276,139,20)
	 screen:blit(164,3,principal,454,313,22,20)
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "tester" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "replace" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    done_apropos = false
		oldpad = pad
	    apropos = Image.load("images/apropos.png")
	    while done_apropos == false do
		  pad = Controls.read()
		  screen:clear()
		  screen:blit(0,0,apropos)
		  if pad:cross() and not oldpad:cross() then done_apropos = true end
		  screen.waitVblankStart()
		  screen.flip()
		  oldpad = pad
	    end
	    statut_menu = "no"
	 end
   oldpad = pad
   end
   if statut_menu=="replace" then
	 screen:blit(185,3,principal,405,313,60,20)
	 screen:blit(185,26,principal,312,352,139,92)
	 screen:blit(185,26,principal,160,276,139,17)
	 if pad:down() and oldpad:down() ~= pad:down() then statut_menu = "find" end
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "?" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "option" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    oldpad=pad
	    replace_gui()
	    statut_menu = "no"
	 end
   oldpad = pad
   end
   if statut_menu=="find" then
	 screen:blit(185,3,principal,405,313,60,20)
	 screen:blit(185,26,principal,312,352,139,92)
	 screen:blit(185,47,principal,160,276,139,17)
	 if pad:down() and oldpad:down() ~= pad:down() then statut_menu = "copy" end
	 if pad:up() and oldpad:up() ~= pad:up() then statut_menu = "replace" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "option" end
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "?" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    oldpad=pad
	    find_gui()
	    statut_menu = "no"
	 end
   oldpad = pad
   end
   if statut_menu=="copy" then
	 screen:blit(185,3,principal,405,313,60,20)
	 screen:blit(185,26,principal,312,352,139,92)
	 screen:blit(185,64,principal,160,276,139,17)
	 if pad:up() and oldpad:up() ~= pad:up() then statut_menu = "find" end
	 if pad:down() and oldpad:down() ~= pad:down() then statut_menu = "paste" end
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "?" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "option" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    if multi_win_nb == 1 and sel1_h_win1 ~= 0 and sel2_h_win1 ~= 0  then
		  tmp_l={}
		  a=1
		  if sel1_h_win1 == sel2_h_win1 then
			tmp_l[1] = string.sub(multi_win_lignes1[sel1_h_win1],sel1_l_win1,sel2_l_win1-1)
			a = 1
		  elseif sel1_h_win1+1 == sel2_h_win1 then
			tmp_l[1] = string.sub(multi_win_lignes1[sel1_h_win1],sel1_l_win1)
			tmp_l[2] = string.sub(multi_win_lignes1[sel2_h_win1],0,sel2_l_win1-1)
			a = 2
		  else
			for i=sel1_h_win1, sel2_h_win1 do
			   if i==sel1_h_win1 then
				 tmp_l[a] = string.sub(multi_win_lignes1[sel1_h_win1],sel1_l_win1)
			   elseif i==sel2_h_win1 then
				 tmp_l[a] = string.sub(multi_win_lignes1[sel2_h_win1],0,sel2_l_win1-1)
			   else
				 tmp_l[a] = multi_win_lignes1[i]
			   end
			   a = a + 1
			end
			a = a - 1
		  end
	    elseif multi_win_nb == 2 and sel1_h_win2 ~= 0 and sel2_h_win2 ~= 0  then
		  tmp_l={}
		  a=1
		  if sel1_h_win2 == sel2_h_win2 then
			tmp_l[1] = string.sub(multi_win_lignes2[sel1_h_win2],sel1_l_win2,sel2_l_win2-1)
			a = 1
		  elseif sel1_h_win2+1 == sel2_h_win2 then
			tmp_l[1] = string.sub(multi_win_lignes2[sel1_h_win2],sel1_l_win2)
			tmp_l[2] = string.sub(multi_win_lignes2[sel2_h_win2],0,sel2_l_win2-1)
			a = 2
		  else
			for i=sel1_h_win2, sel2_h_win2 do
			   if i==sel1_h_win2 then
				 tmp_l[a] = string.sub(multi_win_lignes2[sel1_h_win2],sel1_l_win2)
			   elseif i==sel2_h_win2 then
				 tmp_l[a] = string.sub(multi_win_lignes2[sel2_h_win2],0,sel2_l_win2-1)
			   else
				 tmp_l[a] = multi_win_lignes2[i]
			   end
			   a = a + 1
			end
			a = a - 1
		  end
	    end
	 sel1_h_win1,sel1_l_win1,sel2_h_win1,sel2_l_win1 = 0,0,0,0
	 sel1_h_win2,sel1_l_win2,sel2_h_win2,sel2_l_win2 = 0,0,0,0
	 statut_menu = "no"
	 end	 
   oldpad = pad
   end
   if statut_menu=="paste" then
	 screen:blit(185,3,principal,405,313,60,20)
	 screen:blit(185,26,principal,312,352,139,92)
	 screen:blit(185,82,principal,160,276,139,17)
	 if pad:up() and oldpad:up() ~= pad:up() then statut_menu = "copy" end
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "?" end
	 if pad:down() and oldpad:down() ~= pad:down() then statut_menu = "clear" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "option" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() and tmp_l[1] ~= nil and tmp_l[1] ~= "" then
	    if autosave_etat == 1 then
		  if multi_win_nb == 1 then
			autosave_win1("tmp/paste1.lua")
		  else
			autosave_win2("tmp/paste2.lua")
		  end
	    end
	    System.currentDirectory(repertoire)
		if multi_win_nb == 1 then
		  texte = multi_win_lignes1[positionH_curseur+debut_multi_win1-1]
		  enleve_debut = string.sub(texte,(xcurseur/8) + 1)
		  enleve_fond = string.sub(texte,0,string.len(texte) - string.len(enleve_debut))
		  l=""
		  if a==1 then
			 l = l..tmp_l[1]
			 texte = enleve_fond..l..enleve_debut
			 multi_win_lignes1[positionH_curseur+debut_multi_win1-1] = texte
			 xcurseur = string.len(multi_win_lignes1[positionH_curseur+debut_multi_win1-1])*8
		  elseif a==2 then
			 multi_win_lignes1[positionH_curseur+debut_multi_win1-1] = enleve_fond..tmp_l[1]
			 table.insert(multi_win_lignes1,positionH_curseur+debut_multi_win1,tmp_l[2]..enleve_debut)
			 n=n+1
			 xcurseur = string.len(multi_win_lignes1[positionH_curseur+debut_multi_win1])*8
		  else
			 multi_win_lignes1[positionH_curseur+debut_multi_win1-1] = enleve_fond..tmp_l[1]
			 i=a-1
			 b=0
		   while i>=2 do
			  table.insert(multi_win_lignes1,positionH_curseur+debut_multi_win1,tmp_l[i])			
			  i=i-1
			  b=b+1
			  n_lignes_win1=n_lignes_win1+1
		   end
			 table.insert(multi_win_lignes1,positionH_curseur+debut_multi_win1+1,tmp_l[a]..enleve_debut)
			 n_lignes_win1=n_lignes_win1+1
			 xcurseur = string.len(multi_win_lignes1[positionH_curseur+debut_multi_win1+1])*8
		  end
		else
		   texte = multi_win_lignes2[positionH_curseur+debut_multi_win2-1]
		  enleve_debut = string.sub(texte,(xcurseur/8) + 1)
		  enleve_fond = string.sub(texte,0,string.len(texte) - string.len(enleve_debut))
		  l=""
		  if a==1 then
			 l = l..tmp_l[1]
			 texte = enleve_fond..l..enleve_debut
			 multi_win_lignes2[positionH_curseur+debut_multi_win2-1] = texte
			 xcurseur = string.len(multi_win_lignes2[positionH_curseur+debut_multi_win2-1])*8
		  elseif a==2 then
			 multi_win_lignes2[positionH_curseur+debut_multi_win2-1] = enleve_fond..tmp_l[1]
			 table.insert(multi_win_lignes2,positionH_curseur+debut_multi_win2,tmp_l[2]..enleve_debut)
			 n=n+1
			 xcurseur = string.len(multi_win_lignes2[positionH_curseur+debut_multi_win2])*8
		  else
			 multi_win_lignes2[positionH_curseur+debut_multi_win2-1] = enleve_fond..tmp_l[1]
			 i=a-1
			 b=0
		   while i>=2 do
			  table.insert(multi_win_lignes2,positionH_curseur+debut_multi_win2,tmp_l[i])			
			  i=i-1
			  b=b+1
			  n_lignes_win2=n_lignes_win2+1
		   end
			 table.insert(multi_win_lignes2,positionH_curseur+debut_multi_win2+1,tmp_l[a]..enleve_debut)
			 n_lignes_win2=n_lignes_win2+1
			 xcurseur = string.len(multi_win_lignes2[positionH_curseur+debut_multi_win2+1])*8
		  end 
		end
	 statut_menu = "no"
	 end
	 oldpad = pad
   end
   if statut_menu=="clear" then
	 screen:blit(185,3,principal,405,313,60,20)
	 screen:blit(185,26,principal,312,352,139,92)
	 screen:blit(185,99,principal,160,276,139,17)
	 if pad:up() and oldpad:up() ~= pad:up() then statut_menu = "paste" end
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "?" end
	 if pad:right() and oldpad:right() ~= pad:right() then statut_menu = "option" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    if autosave_etat == 1 then
		  if multi_win_nb == 1 then
			autosave_win1("tmp/clear1.lua")
		  else
			autosave_win2("tmp/clear2.lua")
		  end
	    end
	    System.currentDirectory(repertoire)
	    if multi_win_nb == 1 and sel1_h_win1 ~= 0 and sel2_h_win1 ~= 0 then
		  tmp_l={}
		  a=1
		  if sel1_h_win1 == sel2_h_win1 then
			 multi_win_lignes1[sel1_h_win1] = string.sub(multi_win_lignes1[sel1_h_win1],0,sel1_l_win1-1) .. string.sub(multi_win_lignes1[sel1_h_win1],sel2_l_win1,string.len(multi_win_lignes1[sel1_h_win1]))
		  elseif sel1_h_win1+1 == sel2_h_win1 then
			 multi_win_lignes1[sel1_h_win1] = string.sub(multi_win_lignes1[sel1_h_win1],0,sel1_l_win1-1)
			 xcurseur = string.len(multi_win_lignes1[sel1_h_win1]) * 8
			 ycurseur = ycurseur - 10
			 multi_win_lignes1[sel1_h_win1] = multi_win_lignes1[sel1_h_win1] .. string.sub(multi_win_lignes1[sel2_h_win1],sel2_l_win1,string.len(multi_win_lignes1[sel2_h_win1]))
			 table.remove(multi_win_lignes1, sel2_h_win1)
		  else
			 for i=sel1_h_win1, sel2_h_win1 do
			    if i==sel1_h_win1 then
				   multi_win_lignes1[sel1_h_win1] = string.sub(multi_win_lignes1[sel1_h_win1],0,sel1_l_win1-1)
				   xcurseur = string.len(multi_win_lignes1[sel1_h_win1]) * 8
				   ycurseur = ycurseur - 10
			    elseif i==sel2_h_win1 then
				   multi_win_lignes1[sel2_h_win1-1] = string.sub(multi_win_lignes1[sel2_h_win1-2],sel2_l_win1,string.len(multi_win_lignes1[sel2_h_win1-1]))
			    else
				   table.remove(multi_win_lignes1, i)
				   n_lignes_win1 = n_lignes_win1 - 1
				   ycurseur = ycurseur - 10
			    end
			 end
		  end
	    elseif multi_win_nb == 2 and sel1_h_win2 ~= 0 and sel2_h_win2 ~= 0 then
		 tmp_l={}
		  a=1
		  if sel1_h_win2 == sel2_h_win2 then
			 multi_win_lignes2[sel1_h_win2] = string.sub(multi_win_lignes2[sel1_h_win2],0,sel1_l_win2-1) .. string.sub(multi_win_lignes2[sel1_h_win2],sel2_l_win2,string.len(multi_win_lignes2[sel1_h_win2]))
		  elseif sel1_h_win2+1 == sel2_h_win2 then
			 multi_win_lignes2[sel1_h_win2] = string.sub(multi_win_lignes2[sel1_h_win2],0,sel1_l_win2-1)
			 xcurseur = string.len(multi_win_lignes2[sel1_h_win2]) * 8
			 ycurseur = ycurseur - 10
			 multi_win_lignes2[sel1_h_win2] = multi_win_lignes2[sel1_h_win2] .. string.sub(multi_win_lignes2[sel2_h_win2],sel2_l_win2,string.len(multi_win_lignes2[sel2_h_win2]))
			 table.remove(multi_win_lignes2, sel2_h_win2)
		  else
			 for i=sel1_h_win2, sel2_h_win2 do
			    if i==sel1_h_win2 then
				   multi_win_lignes2[sel1_h_win2] = string.sub(multi_win_lignes2[sel1_h_win2],0,sel1_l_win2-1)
				   xcurseur = string.len(multi_win_lignes2[sel1_h_win2]) * 8
				   ycurseur = ycurseur - 10
			    elseif i==sel2_h_win2 then
				   multi_win_lignes1[sel2_h_win2-1] = string.sub(multi_win_lignes2[sel2_h_win2-2],sel2_l_win2,string.len(multi_win_lignes2[sel2_h_win2-1]))
			    else
				   table.remove(multi_win_lignes2, i)
				   n_lignes_win2 = n_lignes_win2 - 1
				   ycurseur = ycurseur - 10
			    end
			 end
		  end
	    end
	    sel1_h_win1,sel1_l_win1,sel2_h_win1,sel2_l_win1 = 0,0,0,0
	    sel1_h_win2,sel1_l_win2,sel2_h_win2,sel2_l_win2 = 0,0,0,0
	    statut_menu = "no"
	 end
	 oldpad = pad
   end
   if statut_menu=="option" then
	 screen:blit(242,22,principal,10,380,139,42)
	 screen:blit(242,3,principal,405,313,60,20)
	 screen:blit(242,26,principal,160,276,139,17)
	 if pad:down() and oldpad:down() ~= pad:down() then statut_menu = "lua fn" end
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "replace" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    option_fn()
	    statut_menu = "no"
	 end
	 oldpad = pad
   end
   if statut_menu=="lua fn" then
	screen:blit(242,22,principal,10,380,139,42)
	 screen:blit(242,3,principal,405,313,60,20)
	 screen:blit(242,45,principal,160,276,139,17)
	 if pad:up() and oldpad:up() ~= pad:up() then statut_menu = "option" end
	 if pad:left() and oldpad:left() ~= pad:left() then statut_menu = "replace" end
	 if pad:cross() and oldpad:cross() ~= pad:cross() then
	    dofile("luafn.lua")
	    oldpad = pad
	    statut_menu = "no"
	 end
	 oldpad = pad
   end
end
 
function aff_text(debut)
   if multi_win_nb == 1  then
	 nlignes = table.getn(multi_win_lignes1)
	 yligne = 50 
	 if debut_multi_win1+22 < nlignes then
	    nb_l = debut_multi_win1 + 22
	 else
	    nb_l = nlignes
	 end
	 for i=debut_multi_win1, nb_l do
	    screen:print(x,yligne,multi_win_lignes1[i])
	    yligne = yligne + 10 
	 end
   elseif multi_win_nb == 2  then
	 nlignes = table.getn(multi_win_lignes2)
	 yligne = 50 
	 if debut_multi_win2+22 < nlignes then
	    nb_l = debut_multi_win2 + 22
	 else
	    nb_l = nlignes
	 end
	 for i=debut_multi_win2, nb_l do
	    screen:print(x,yligne,multi_win_lignes2[i])
	    yligne = yligne + 10 
	 end
   end
end

function syntaxe_win1()
   nx = table.getn(multi_win_lignes1)
   yligne = 50 
   if debut_multi_win1+22 < nx then
	 nb_l = debut_multi_win1 + 22
   else
	 nb_l = nx
   end

   for i=debut_multi_win1, nb_l do 
	 
	 -- do

	 if string.find(multi_win_lignes1[i],"do") ~= nil then
	    if string.find(multi_win_lignes1[i],"do ") ~= nil or string.find(multi_win_lignes1[i],"do")+1 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"do")-1)*8,yligne,"do",rouge)
	    end
	 end

	 -- if

	 if string.find(multi_win_lignes1[i],"if") ~= nil then
	    if string.find(multi_win_lignes1[i],"if ") ~= nil or string.find(multi_win_lignes1[i],"if")+1 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"if")-1)*8,yligne,"if",rouge)
	    end
	 end

	 -- for

	 if string.find(multi_win_lignes1[i],"for") ~= nil then
	    if string.find(multi_win_lignes1[i],"for ") ~= nil or string.find(multi_win_lignes1[i],"for")+2 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"for")-1)*8,yligne,"for",rouge)
	    end
	 end

	 -- while

	 if string.find(multi_win_lignes1[i],"while") ~= nil then
	    if string.find(multi_win_lignes1[i],"while ") ~= nil or string.find(multi_win_lignes1[i],"while")+4 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"while")-1)*8,yligne,"while",rouge)
	    end
	 end
 
	 -- then

	 if string.find(multi_win_lignes1[i],"then") ~= nil then
	    if string.find(multi_win_lignes1[i],"then ") ~= nil or string.find(multi_win_lignes1[i],"then")+3 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"then")-1)*8,yligne,"then",rouge)
	    end
	 end

	 -- end

	 if string.find(multi_win_lignes1[i],"end") ~= nil then
	    if string.find(multi_win_lignes1[i],"end ") ~= nil or string.find(multi_win_lignes1[i],"end")+2 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"end")-1)*8,yligne,"end",rouge)
	    end
	 end

	 -- commentaire

	 if string.sub(multi_win_lignes1[i],0,2)  == "--" then 
	    screen:print(0,yligne,multi_win_lignes1[i],vert)
	 end

	 -- true

	 if string.find(multi_win_lignes1[i],"true") ~= nil then
	    if string.find(multi_win_lignes1[i],"true ") ~= nil or string.find(multi_win_lignes1[i],"true")+3 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"true")-1)*8,yligne,"true",violet)
	    end
	 end

	 -- false

	 if string.find(multi_win_lignes1[i],"false") ~= nil then
	    if string.find(multi_win_lignes1[i],"false ") ~= nil or string.find(multi_win_lignes1[i],"false")+4 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"false")-1)*8,yligne,"false",violet)
	    end
	 end

	 -- nil

	 if string.find(multi_win_lignes1[i],"nil") ~= nil then
	    if string.find(multi_win_lignes1[i],"nil ") ~= nil or string.find(multi_win_lignes1[i],"nil")+2 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"nil")-1)*8,yligne,"nil",violet)
	    end
	 end

	 -- Controls

	 if string.find(multi_win_lignes1[i],"Controls") ~= nil then
	    if string.find(multi_win_lignes1[i],"Controls.") ~= nil then
		  screen:print((string.find(multi_win_lignes1[i],"Controls.")-1)*8,yligne,"Controls.",orange)
	    end
	 end

	 -- System

	 if string.find(multi_win_lignes1[i],"System") ~= nil then
	    if string.find(multi_win_lignes1[i],"System.") ~= nil then
		  screen:print((string.find(multi_win_lignes1[i],"System.")-1)*8,yligne,"System.",orange)
	    end
	 end

	 -- break

	 if string.find(multi_win_lignes1[i],"break") ~= nil then
	    if string.find(multi_win_lignes1[i],"break ") ~= nil or string.find(multi_win_lignes1[i],"break")+4 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"break")-1)*8,yligne,"break",orange)
	    end
	 end

	 -- return

	 if string.find(multi_win_lignes1[i],"return") ~= nil then
	    if string.find(multi_win_lignes1[i],"return ") ~= nil or string.find(multi_win_lignes1[i],"return")+5 == string.len(multi_win_lignes1[i]) then
		  screen:print((string.find(multi_win_lignes1[i],"return")-1)*8,yligne,"return",orange)
	    end
	 end
	 
	 -- screen.

	 if string.find(multi_win_lignes1[i],"screen.") ~= nil then
	    screen:print((string.find(multi_win_lignes1[i],"screen.")-1)*8,yligne,"screen.",bleu)
	 end

	 -- screen:

	 if string.find(multi_win_lignes1[i],"screen:") ~= nil then
	    screen:print((string.find(multi_win_lignes1[i],"screen:")-1)*8,yligne,"screen:",bleu)
	 end

	 yligne = yligne + 10
   end
end

function syntaxe_win2()
   nx = table.getn(multi_win_lignes2)
   yligne = 50 
   if debut_multi_win2+22 < nx then
	 nb_l = debut_multi_win2 + 22
   else
	 nb_l = nx
   end

   for i=debut_multi_win2, nb_l do 
	 
	 -- do

	 if string.find(multi_win_lignes2[i],"do") ~= nil then
	    if string.find(multi_win_lignes2[i],"do ") ~= nil or string.find(multi_win_lignes2[i],"do")+1 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"do")-1)*8,yligne,"do",rouge)
	    end
	 end

	 -- if

	 if string.find(multi_win_lignes2[i],"if") ~= nil then
	    if string.find(multi_win_lignes2[i],"if ") ~= nil or string.find(multi_win_lignes2[i],"if")+1 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"if")-1)*8,yligne,"if",rouge)
	    end
	 end

	 -- for

	 if string.find(multi_win_lignes2[i],"for") ~= nil then
	    if string.find(multi_win_lignes2[i],"for ") ~= nil or string.find(multi_win_lignes2[i],"for")+2 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"for")-1)*8,yligne,"for",rouge)
	    end
	 end

	 -- while

	 if string.find(multi_win_lignes2[i],"while") ~= nil then
	    if string.find(multi_win_lignes2[i],"while ") ~= nil or string.find(multi_win_lignes2[i],"while")+4 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"while")-1)*8,yligne,"while",rouge)
	    end
	 end
 
	 -- then

	 if string.find(multi_win_lignes2[i],"then") ~= nil then
	    if string.find(multi_win_lignes2[i],"then ") ~= nil or string.find(multi_win_lignes2[i],"then")+3 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"then")-1)*8,yligne,"then",rouge)
	    end
	 end

	 -- end

	 if string.find(multi_win_lignes2[i],"end") ~= nil then
	    if string.find(multi_win_lignes2[i],"end ") ~= nil or string.find(multi_win_lignes2[i],"end")+2 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"end")-1)*8,yligne,"end",rouge)
	    end
	 end

	 -- commentaire

	 if string.sub(multi_win_lignes2[i],0,2)  == "--" then 
	    screen:print(0,yligne,multi_win_lignes2[i],vert)
	 end

	 -- true

	 if string.find(multi_win_lignes2[i],"true") ~= nil then
	    if string.find(multi_win_lignes2[i],"true ") ~= nil or string.find(multi_win_lignes2[i],"true")+3 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"true")-1)*8,yligne,"true",violet)
	    end
	 end

	 -- false

	 if string.find(multi_win_lignes2[i],"false") ~= nil then
	    if string.find(multi_win_lignes2[i],"false ") ~= nil or string.find(multi_win_lignes2[i],"false")+4 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"false")-1)*8,yligne,"false",violet)
	    end
	 end

	 -- nil

	 if string.find(multi_win_lignes2[i],"nil") ~= nil then
	    if string.find(multi_win_lignes2[i],"nil ") ~= nil or string.find(multi_win_lignes2[i],"nil")+2 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"nil")-1)*8,yligne,"nil",violet)
	    end
	 end

	 -- Controls

	 if string.find(multi_win_lignes2[i],"Controls") ~= nil then
	    if string.find(multi_win_lignes2[i],"Controls.") ~= nil then
		  screen:print((string.find(multi_win_lignes2[i],"Controls.")-1)*8,yligne,"Controls.",orange)
	    end
	 end

	 -- System

	 if string.find(multi_win_lignes2[i],"System") ~= nil then
	    if string.find(multi_win_lignes2[i],"System.") ~= nil then
		  screen:print((string.find(multi_win_lignes2[i],"System.")-1)*8,yligne,"System.",orange)
	    end
	 end

	 -- break

	 if string.find(multi_win_lignes2[i],"break") ~= nil then
	    if string.find(multi_win_lignes2[i],"break ") ~= nil or string.find(multi_win_lignes2[i],"break")+4 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"break")-1)*8,yligne,"break",orange)
	    end
	 end

	 -- return

	 if string.find(multi_win_lignes2[i],"return") ~= nil then
	    if string.find(multi_win_lignes2[i],"return ") ~= nil or string.find(multi_win_lignes2[i],"return")+5 == string.len(multi_win_lignes2[i]) then
		  screen:print((string.find(multi_win_lignes2[i],"return")-1)*8,yligne,"return",orange)
	    end
	 end
	 
	 -- screen.

	 if string.find(multi_win_lignes2[i],"screen.") ~= nil then
	    screen:print((string.find(multi_win_lignes2[i],"screen.")-1)*8,yligne,"screen.",bleu)
	 end

	 -- screen:

	 if string.find(multi_win_lignes2[i],"screen:") ~= nil then
	    screen:print((string.find(multi_win_lignes2[i],"screen:")-1)*8,yligne,"screen:",bleu)
	 end

	 yligne = yligne + 10
   end
end

function cursor_win1()
   screen:blit(xcurseur,ycurseur,curseur)
   if pad:right() and oldpad:right() ~= pad:right() and statut_menu=="no" and xcurseur ~= 488 and string.sub(multi_win_lignes1[positionH_curseur + debut_multi_win1-1], (xcurseur/8)+1, (xcurseur/8)+1) ~= "" then xcurseur = xcurseur + 8 end
   if pad:left() and oldpad:left() ~= pad:left() and statut_menu=="no" and xcurseur ~= 0 then xcurseur = xcurseur - 8 end
   if pad:down() and oldpad:down() ~= pad:down() and statut_menu=="no" and ycurseur ~= 249 then
	 if positionH_curseur + debut_multi_win1 <= n_lignes_win1 then
	    ycurseur = ycurseur +10
	    if string.len(multi_win_lignes1[positionH_curseur + debut_multi_win1]) < xcurseur/8 then
		  xcurseur = string.len(multi_win_lignes1[positionH_curseur + debut_multi_win1])*8
	    end
	 end
   end
   if pad:up() and oldpad:up() ~= pad:up() and statut_menu=="no" and ycurseur ~= 49 then 
	 ycurseur = ycurseur - 10
	 if positionH_curseur + debut_multi_win1-2 > 1 then
	    if string.len(multi_win_lignes1[positionH_curseur + debut_multi_win1-2]) < xcurseur/8 then
		  xcurseur = string.len(multi_win_lignes1[positionH_curseur + debut_multi_win1-2])*8
	    end
	 end
   end
   if pad:analogX() > 90 and statut_menu=="no" and aff_clavier == false and string.sub(multi_win_lignes1[positionH_curseur + debut_multi_win1-1], (xcurseur/8)+1, (xcurseur/8)+1) ~= "" then xcurseur = xcurseur + 8 end
   if pad:analogX() < -90 and aff_clavier == false and statut_menu=="no" then xcurseur = xcurseur - 8 end
   if pad:analogY() > 90 and aff_clavier == false and statut_menu=="no" then 
	 if positionH_curseur + debut_multi_win1 <= n_lignes_win1 then
	    ycurseur = ycurseur +10
	    if string.len(multi_win_lignes1[positionH_curseur + debut_multi_win1]) < xcurseur/8 then
		  xcurseur = string.len(multi_win_lignes1[positionH_curseur + debut_multi_win1])*8
	    end
	 end
   end
   if pad:analogY() < -90 and statut_menu=="no" and aff_clavier == false then 
	 ycurseur = ycurseur - 10
	 if positionH_curseur + debut_multi_win1-2 > 1 then
	    if string.len(multi_win_lignes1[positionH_curseur + debut_multi_win1-2]) < xcurseur/8 then
		  xcurseur = string.len(multi_win_lignes1[positionH_curseur + debut_multi_win1-2])*8
	    end
	 end
   end
   if ycurseur < 49 then
	 if debut_multi_win1 > 1 then debut_multi_win1 = debut_multi_win1 - 1 end
	 ycurseur = 49
   end
   if ycurseur > 249 then
	 debut_multi_win1 = debut_multi_win1 + 1
	 ycurseur = 249
   end
   if xcurseur > 464 and pad:analogX() > 50 and aff_clavier == false and statut_menu=="no" then
	 if i_defilement_horizontal_win1 == 0 then
	   i_defilement_horizontal_win1 = i_defilement_horizontal_win1 + 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		multi_win1_temp_ligne = {}
		multi_win1_sauv_ligne = {}
		for id=1, n_lignes_defilement do
			multi_win1_temp_ligne[id] = multi_win_lignes1[id]
			longueur_ligne_dh = string.len(multi_win_lignes1[id])
			multi_win1_sauv_ligne[id] = string.sub(multi_win1_temp_ligne[id],0,i_defilement_horizontal_win1*60)
			multi_win_lignes1[id] = string.sub(multi_win1_temp_ligne[id],61)
			tre = multi_win1_sauv_ligne[id]
			xcurseur = 0
		end
	 elseif i_defilement_horizontal_win1 == 1 then
	   i_defilement_horizontal_win1 = i_defilement_horizontal_win1 + 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		multi_win1_temp_ligne1 = {}
		multi_win1_sauv_ligne1 = {}
		for id=1, n_lignes_defilement do
			multi_win1_temp_ligne1[id] = multi_win_lignes1[id]
			longueur_ligne_dh = string.len(multi_win_lignes1[id])
			multi_win1_sauv_ligne1[id] = string.sub(multi_win1_temp_ligne1[id],0,60)
			multi_win_lignes1[id] = string.sub(multi_win1_temp_ligne1[id],61)
			tre = multi_win1_sauv_ligne1[id]
			xcurseur = 0
		end
	 elseif i_defilement_horizontal_win1 == 2 then
	   i_defilement_horizontal_win1 = i_defilement_horizontal_win1 + 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		multi_win1_temp_ligne2 = {}
		multi_win1_sauv_ligne2 = {}
		for id=1, n_lignes_defilement do
			multi_win1_temp_ligne2[id] = multi_win_lignes1[id]
			longueur_ligne_dh = string.len(multi_win_lignes1[id])
			multi_win1_sauv_ligne2[id] = string.sub(multi_win1_temp_ligne2[id],0,60)
			multi_win_lignes1[id] = string.sub(multi_win1_temp_ligne2[id],61)
			tre = multi_win1_sauv_ligne2[id]
			xcurseur = 0
		end
	 elseif i_defilement_horizontal_win1 == 3 then
	    i_defilement_horizontal_win1 = i_defilement_horizontal_win1 + 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		multi_win1_temp_ligne3 = {}
		multi_win1_sauv_ligne3 = {}
		for id=1, n_lignes_defilement do
			multi_win1_temp_ligne3[id] = multi_win_lignes1[id]
			longueur_ligne_dh = string.len(multi_win_lignes1[id])
			multi_win1_sauv_ligne3[id] = string.sub(multi_win1_temp_ligne3[id],0,60)
			multi_win_lignes1[id] = string.sub(multi_win1_temp_ligne3[id],61)
			tre = multi_win1_sauv_ligne3[id]
			xcurseur = 0
		end
	 end
   end
   if xcurseur < 0 and statut_menu=="no" and pad:analogX() < -50 and i_defilement_horizontal_win1 == 1 and aff_clavier == false then
		i_defilement_horizontal_win1 = i_defilement_horizontal_win1 - 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		for id=1, n_lignes_defilement do
			multi_win_lignes1[id] = multi_win1_sauv_ligne[id]..multi_win_lignes1[id]
			xcurseur = 472
		end
   end
   if xcurseur < 0 and statut_menu=="no" and pad:analogX() < -50 and i_defilement_horizontal_win1 == 2 and aff_clavier == false then
		i_defilement_horizontal_win1 = i_defilement_horizontal_win1 - 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		for id=1, n_lignes_defilement do
			multi_win_lignes1[id] = multi_win1_sauv_ligne1[id]..multi_win_lignes1[id]
			xcurseur = 472
		end
   end
   if xcurseur < 0 and statut_menu=="no" and pad:analogX() < -50 and i_defilement_horizontal_win1 == 3 and aff_clavier == false then
		i_defilement_horizontal_win1 = i_defilement_horizontal_win1 - 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		for id=1, n_lignes_defilement do
			multi_win_lignes1[id] = multi_win1_sauv_ligne2[id]..multi_win_lignes1[id]
			xcurseur = 472
		end
   end
   if xcurseur < 0 and statut_menu=="no" and pad:analogX() < -50 and i_defilement_horizontal_win1 == 4 and aff_clavier == false then
		i_defilement_horizontal_win1 = i_defilement_horizontal_win1 - 1
		n_lignes_defilement = table.getn(multi_win_lignes1)
		for id=1, n_lignes_defilement do
			multi_win_lignes1[id] = multi_win1_sauv_ligne3[id]..multi_win_lignes1[id]
			xcurseur = 472
		end
   end
   if xcurseur < 0 then xcurseur = 0 end
   if xcurseur > 480 then xcurseur = 480 end
 
   positionL_curseur = xcurseur / 8 + 1
   positionH_curseur = (ycurseur - 49) /10 + 1
   if i_defilement_horizontal_win1 == 1 then positionL_curseur = positionL_curseur + 60 end
   if i_defilement_horizontal_win1 == 2 then positionL_curseur = positionL_curseur + 120 end
   if i_defilement_horizontal_win1 == 3 then positionL_curseur = positionL_curseur + 180 end
   if i_defilement_horizontal_win1 == 4 then positionL_curseur = positionL_curseur + 240 end
   if positionH_curseur+debut_multi_win1-1 > nlignes then
	 ycurseur = ycurseur - 10
   end
end

function cursor_win2()
   screen:blit(xcurseur,ycurseur,curseur)
   if pad:right() and oldpad:right() ~= pad:right() and statut_menu=="no" and xcurseur ~= 488 and string.sub(multi_win_lignes2[positionH_curseur + debut_multi_win2-1], (xcurseur/8)+1, (xcurseur/8)+1) ~= "" then xcurseur = xcurseur + 8 end
   if pad:left() and oldpad:left() ~= pad:left() and statut_menu=="no" and xcurseur ~= 0 then xcurseur = xcurseur - 8 end
   if pad:down() and oldpad:down() ~= pad:down() and statut_menu=="no" and ycurseur ~= 249 then
	 if positionH_curseur + debut_multi_win2 <= n_lignes_win2 then
	    ycurseur = ycurseur +10
	    if string.len(multi_win_lignes2[positionH_curseur + debut_multi_win2]) < xcurseur/8 then
		  xcurseur = string.len(multi_win_lignes2[positionH_curseur + debut_multi_win2])*8
	    end
	 end
   end
   if pad:up() and oldpad:up() ~= pad:up() and statut_menu=="no" and ycurseur ~= 49 then 
	 ycurseur = ycurseur - 10
	 if positionH_curseur + debut_multi_win2-2 > 1 then
	    if string.len(multi_win_lignes2[positionH_curseur + debut_multi_win2-2]) < xcurseur/8 then
		  xcurseur = string.len(multi_win_lignes2[positionH_curseur + debut_multi_win2-2])*8
	    end
	 end
   end
   if pad:analogX() > 90 and statut_menu=="no" and aff_clavier == false and string.sub(multi_win_lignes2[positionH_curseur + debut_multi_win2-1], (xcurseur/8)+1, (xcurseur/8)+1) ~= "" then xcurseur = xcurseur + 8 end
   if pad:analogX() < -90 and aff_clavier == false and statut_menu=="no" then xcurseur = xcurseur - 8 end
   if pad:analogY() > 90 and aff_clavier == false and statut_menu=="no" then 
	 if positionH_curseur + debut_multi_win2 <= n_lignes_win2 then
	    ycurseur = ycurseur + 10
	    if string.len(multi_win_lignes2[positionH_curseur + debut_multi_win2]) < xcurseur/8 then
		  xcurseur = string.len(multi_win_lignes2[positionH_curseur + debut_multi_win2])*8
	    end
	 end
   end
   if pad:analogY() < -90 and statut_menu=="no" and aff_clavier == false then 
	 ycurseur = ycurseur - 10
	 if positionH_curseur + debut_multi_win2-2 > 1 then
	    if string.len(multi_win_lignes2[positionH_curseur + debut_multi_win2-2]) < xcurseur/8 then
		  xcurseur = string.len(multi_win_lignes2[positionH_curseur + debut_multi_win2-2])*8
	    end
	 end
   end
   if ycurseur < 49 then
	 if debut_multi_win2 > 1 then debut_multi_win2 = debut_multi_win2 - 1 end
	 ycurseur = 49
   end
   if ycurseur > 249 then
	 debut_multi_win2 = debut_multi_win2 + 1
	 ycurseur = 249
   end
   if xcurseur > 464 and pad:analogX() > 50 and aff_clavier == false and statut_menu=="no" then
	 if i_defilement_horizontal_win2 == 0 then
	   i_defilement_horizontal_win2 = i_defilement_horizontal_win2 + 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		multi_win2_temp_ligne = {}
		multi_win2_sauv_ligne = {}
		for id=1, n_lignes_defilement do
			multi_win2_temp_ligne[id] = multi_win_lignes2[id]
			longueur_ligne_dh = string.len(multi_win_lignes2[id])
			multi_win2_sauv_ligne[id] = string.sub(multi_win2_temp_ligne[id],0,i_defilement_horizontal_win2*60)
			multi_win_lignes2[id] = string.sub(multi_win2_temp_ligne[id],61)
			tre = multi_win2_sauv_ligne[id]
			xcurseur = 0
		end
	 elseif i_defilement_horizontal_win2 == 1 then
	   i_defilement_horizontal_win2 = i_defilement_horizontal_win2 + 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		multi_win2_temp_ligne1 = {}
		multi_win2_sauv_ligne1 = {}
		for id=1, n_lignes_defilement do
			multi_win2_temp_ligne1[id] = multi_win_lignes2[id]
			longueur_ligne_dh = string.len(multi_win_lignes2[id])
			multi_win2_sauv_ligne1[id] = string.sub(multi_win2_temp_ligne1[id],0,60)
			multi_win_lignes2[id] = string.sub(multi_win2_temp_ligne1[id],61)
			tre = multi_win2_sauv_ligne1[id]
			xcurseur = 0
		end
	 elseif i_defilement_horizontal_win2 == 2 then
	   i_defilement_horizontal_win2 = i_defilement_horizontal_win2 + 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		multi_win2_temp_ligne2 = {}
		multi_win2_sauv_ligne2 = {}
		for id=1, n_lignes_defilement do
			multi_win2_temp_ligne2[id] = multi_win_lignes2[id]
			longueur_ligne_dh = string.len(multi_win_lignes2[id])
			multi_win2_sauv_ligne2[id] = string.sub(multi_win2_temp_ligne2[id],0,60)
			multi_win_lignes2[id] = string.sub(multi_win2_temp_ligne2[id],61)
			tre = multi_win2_sauv_ligne2[id]
			xcurseur = 0
		end
	 elseif i_defilement_horizontal_win2 == 3 then
	    i_defilement_horizontal_win2 = i_defilement_horizontal_win2 + 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		multi_win2_temp_ligne3 = {}
		multi_win2_sauv_ligne3 = {}
		for id=1, n_lignes_defilement do
			multi_win2_temp_ligne3[id] = multi_win_lignes2[id]
			longueur_ligne_dh = string.len(multi_win_lignes2[id])
			multi_win2_sauv_ligne3[id] = string.sub(multi_win2_temp_ligne3[id],0,60)
			multi_win_lignes2[id] = string.sub(multi_win2_temp_ligne3[id],61)
			tre = multi_win2_sauv_ligne3[id]
			xcurseur = 0
		end
	 end
   end
   if xcurseur < 0 and statut_menu=="no" and pad:analogX() < -50 and i_defilement_horizontal_win2 == 1 and aff_clavier == false then
		i_defilement_horizontal_win2 = i_defilement_horizontal_win2 - 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		for id=1, n_lignes_defilement do
			multi_win_lignes2[id] = multi_win2_sauv_ligne[id]..multi_win_lignes2[id]
			xcurseur = 472
		end
   end
   if xcurseur < 0 and statut_menu=="no" and pad:analogX() < -50 and i_defilement_horizontal_win2 == 2 and aff_clavier == false then
		i_defilement_horizontal_win2 = i_defilement_horizontal_win2 - 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		for id=1, n_lignes_defilement do
			multi_win_lignes2[id] = multi_win2_sauv_ligne1[id]..multi_win_lignes2[id]
			xcurseur = 472
		end
   end
   if xcurseur < 0 and statut_menu=="no" and pad:analogX() < -50 and i_defilement_horizontal_win2 == 3 and aff_clavier == false then
		i_defilement_horizontal_win2 = i_defilement_horizontal_win2 - 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		for id=1, n_lignes_defilement do
			multi_win_lignes2[id] = multi_win2_sauv_ligne2[id]..multi_win_lignes2[id]
			xcurseur = 472
		end
   end
   if xcurseur < 0 and statut_menu=="no" and pad:analogX() < -50 and i_defilement_horizontal_win2 == 4 and aff_clavier == false then
		i_defilement_horizontal_win2 = i_defilement_horizontal_win2 - 1
		n_lignes_defilement = table.getn(multi_win_lignes2)
		for id=1, n_lignes_defilement do
			multi_win_lignes2[id] = multi_win2_sauv_ligne3[id]..multi_win_lignes2[id]
			xcurseur = 472
		end
   end
   if xcurseur < 0 then xcurseur = 0 end
   if xcurseur > 480 then xcurseur = 480 end
 
   positionL_curseur = xcurseur / 8 + 1
   positionH_curseur = (ycurseur - 49) /10 + 1
   if i_defilement_horizontal_win2 == 1 then positionL_curseur = positionL_curseur + 60 end
   if i_defilement_horizontal_win2 == 2 then positionL_curseur = positionL_curseur + 120 end
   if i_defilement_horizontal_win2 == 3 then positionL_curseur = positionL_curseur + 180 end
   if i_defilement_horizontal_win2 == 4 then positionL_curseur = positionL_curseur + 240 end
   if positionH_curseur+debut_multi_win2-1 > nlignes then
	 ycurseur = ycurseur - 10
   end
end

function aff_clavier_()
	if pad:l() and oldpad:l() ~= pad:l() then
		if type_clavier == 1 then
			type_clavier = 2
		elseif type_clavier == 2 then
			type_clavier = 1
		end
	end
	if pad:r() then
		if type_clavier == 1 then
			type_clavier2 = 1
		end
		if type_clavier == 2 then
			type_clavier2 = 2
		end
	else
		type_clavier2 = 0
	end
	
		
		
   if type_clavier == 1 and type_clavier2 ~= 1 then
	screen:blit(clavier_x,100,clavier,0,0,151,151)
	 --milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+51,151,clavier,202,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then effacer() end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("m") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre(" ") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("n") end
	 end
	 --haut gauche
	 if pad:analogX() < -50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+1,101,clavier,152,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre(",") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("a") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("b") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("c") end
	 end
	 --haut milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+51,101,clavier,202,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre(".") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("d") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("e") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("f") end
	 end
	 --haut droite
	 if pad:analogX() > 50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+101,101,clavier,252,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("!") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("g") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("h") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("i") end
	 end
	 --gauche
	 if pad:analogX() < -50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+1,151,clavier,152,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("-") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("j") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("k") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("l") end
	 end
	 --droite
	 if pad:analogX() > 50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+101,151,clavier,252,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("?") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("o") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("p") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("q") end
	 end
	 --bas gauche
	 if pad:analogX() < -50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+1,201,clavier,152,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("(") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("r") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("s") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("t") end
	 end
	 --bas milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+51,201,clavier,202,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre(":") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("u") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("v") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("w") end
	 end
	 --bas droite
	 if pad:analogX() > 50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+101,201,clavier,252,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre(")") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("x") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("y") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("z") end
	 end
   end
   if type_clavier == 2 and type_clavier2 ~= 2 then
		screen:blit(clavier_x,100,clavier1,0,0,151,151)
	 --milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+51,151,clavier1,202,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then effacer() end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre(" ") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("5") end
	 end
	 --haut gauche
	 if pad:analogX() < -50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+1,101,clavier1,152,1,49,49)
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("1") end
	 end
	 --haut milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+51,101,clavier1,202,1,49,49)
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("2") end
	 end
	 --haut droite
	 if pad:analogX() > 50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+101,101,clavier1,252,1,49,49)
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("3") end
	 end
	 --gauche
	 if pad:analogX() < -50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+1,151,clavier1,152,51,49,49)
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("4") end
	 end
	 --droite
	 if pad:analogX() > 50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+101,151,clavier1,252,51,49,49)
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("6") end
	 end
	 --bas gauche
	 if pad:analogX() < -50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+1,201,clavier1,152,101,49,49)
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("7") end
	 end
	 --bas milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+51,201,clavier1,202,101,49,49)
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("8") end
	 end
	 --bas droite
	 if pad:analogX() > 50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+101,201,clavier1,252,101,49,49)
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("0") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("9") end
	 end
   end
	
	if type_clavier2 == 1 then
	screen:blit(clavier_x,100,clavier2,0,0,151,151)
	 --milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+51,151,clavier2,202,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then effacer() end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("M") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre(" ") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("N") end
	 end
	 --haut gauche
	 if pad:analogX() < -50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+1,101,clavier2,152,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("^") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("A") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("B") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("C") end
	 end
	 --haut milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+51,101,clavier2,202,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("@") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("D") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("E") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("F") end
	 end
	 --haut droite
	 if pad:analogX() > 50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+101,101,clavier2,252,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("*") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("G") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("H") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("I") end
	 end
	 --gauche
	 if pad:analogX() < -50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+1,151,clavier2,152,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("_") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("J") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("K") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("L") end
	 end
	 --droite
	 if pad:analogX() > 50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+101,151,clavier2,252,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("\"") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("O") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("P") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("Q") end
	 end
	 --bas gauche
	 if pad:analogX() < -50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+1,201,clavier2,152,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("=") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("R") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("S") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("T") end
	 end
	 --bas milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+51,201,clavier2,202,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre(";") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("U") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("V") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("W") end
	 end
	 --bas droite
	 if pad:analogX() > 50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+101,201,clavier2,252,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("/") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("X") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("Y") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("Z") end
	 end
   end
	if type_clavier2 == 2 then
	screen:blit(clavier_x,100,clavier3,0,0,151,151)
	 --milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+51,151,clavier3,202,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then effacer() end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre(" ") end
	 end
	 --haut gauche
	 if pad:analogX() < -50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+1,101,clavier3,152,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre(",") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("(") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre(".") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre(")") end
	 end
	 --haut milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+51,101,clavier3,202,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("\"") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("<") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("'") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre(">") end
	 end
	 --haut droite
	 if pad:analogX() > 50 and pad:analogY() < -50 then
	    screen:blit(clavier_x+101,101,clavier3,252,1,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("-") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("[") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("_") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("]") end
	 end
	 --gauche
	 if pad:analogX() < -50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+1,151,clavier3,152,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("!") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("{") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("?") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("}") end
	 end
	 --droite
	 if pad:analogX() > 50 and pad:analogY() > -50 and pad:analogY() < 50 then
	    screen:blit(clavier_x+101,151,clavier3,252,51,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("+") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("\\") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("=") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("/") end
	 end
	 --bas gauche
	 if pad:analogX() < -50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+1,201,clavier3,152,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre(":") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("@") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre(";") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("#") end
	 end
	 --bas milieu
	 if pad:analogX() > -50 and pad:analogX() < 50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+51,201,clavier3,202,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("~") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("$") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("`") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("%") end
	 end
	 --bas droite
	 if pad:analogX() > 50 and pad:analogY() > 50 then
	    screen:blit(clavier_x+101,201,clavier3,252,101,49,49)
	    if pad:triangle() and oldpad:triangle() ~= pad:triangle() then ajouter_lettre("*") end
	    if pad:square() and oldpad:square() ~= pad:square() then ajouter_lettre("^") end
	    if pad:cross() and oldpad:cross() ~= pad:cross() then ajouter_lettre("|") end
	    if pad:circle() and oldpad:circle() ~= pad:circle() then ajouter_lettre("&") end
	 end
   end
end   
 
function ajouter_lettre(lettre)
   if multi_win_nb == 1 then
	 texte = multi_win_lignes1[positionH_curseur+debut_multi_win1-1]
	 if texte == nil then
	    table.insert(multi_win_lignes1, positionH_curseur+debut_multi_win1-1, lettre)
	 else
	    enleve_debut = string.sub(texte,(xcurseur/8) + 1)
	    enleve_fond = string.sub(texte,0,string.len(texte) - string.len(enleve_debut))
	    multi_win_lignes1[positionH_curseur+debut_multi_win1-1] = enleve_fond .. lettre .. enleve_debut
	    xcurseur = xcurseur + 8
	 end
   else
	 texte = multi_win_lignes2[positionH_curseur+debut_multi_win2-1]
	 if texte == nil then
	    table.insert(multi_win_lignes2, positionH_curseur+debut_multi_win2-1, lettre)
	 else
	    enleve_debut = string.sub(texte,(xcurseur/8) + 1)
	    enleve_fond = string.sub(texte,0,string.len(texte) - string.len(enleve_debut))
	    multi_win_lignes2[positionH_curseur+debut_multi_win2-1] = enleve_fond .. lettre .. enleve_debut
	    xcurseur = xcurseur + 8
	 end
   end
end

function effacer()
   if multi_win_nb == 1 then
	 texte = multi_win_lignes1[positionH_curseur+debut_multi_win1-1]
	 if texte == nil then
	    table.remove(multi_win_lignes1, positionH_curseur+debut_multi_win1-1)
	    n_lignes_win1=n_lignes_win1-1
	 elseif texte=="" then
	    table.remove(multi_win_lignes1, positionH_curseur+debut_multi_win1-1)
	    ycurseur = ycurseur -10
	    xcurseur = string.len(multi_win_lignes1[positionH_curseur+debut_multi_win1-2])*8
	    n_lignes_win1 = n_lignes_win1-1
	 elseif xcurseur == 0 and texte~=nil and ycurseur>29 then
	    xcurseur=string.len(multi_win_lignes1[positionH_curseur+debut_multi_win1-2])*8
	    multi_win_lignes1[positionH_curseur+debut_multi_win1-2]=multi_win_lignes1[positionH_curseur+debut_multi_win1-2]..multi_win_lignes1[positionH_curseur+debut_multi_win1-1]
	    table.remove(multi_win_lignes1, positionH_curseur+debut-1)
	    ycurseur = ycurseur -10
	    n_lignes_win1=n_lignes_win1-1
	 elseif xcurseur==0 then
	 else
	    enleve_debut = string.sub(texte,(xcurseur/8) + 1)
	    enleve_fond = string.sub(texte,0,string.len(texte) - string.len(enleve_debut) - 1)
	    tout = enleve_fond .. enleve_debut
	    multi_win_lignes1[positionH_curseur+debut_multi_win1-1] = tout
	    xcurseur = xcurseur - 8
	 end
   else
	 texte = multi_win_lignes2[positionH_curseur+debut_multi_win2-1]
	 if texte == nil then
	    table.remove(multi_win_lignes2, positionH_curseur+debut_multi_win2-1)
	    n_lignes_win2=n_lignes_win2-1
	 elseif texte=="" then
	    table.remove(multi_win_lignes2, positionH_curseur+debut_multi_win2-1)
	    ycurseur = ycurseur -10
	    xcurseur = string.len(multi_win_lignes2[positionH_curseur+debut_multi_win2-2])*8
	    n_lignes_win2=n_lignes_win2-1
	 elseif xcurseur == 0 and texte~=nil and ycurseur>29 then
	    xcurseur=string.len(multi_win_lignes2[positionH_curseur+debut_multi_win2-2])*8
	    multi_win_lignes2[positionH_curseur+debut_multi_win2-2]=multi_win_lignes2[positionH_curseur+debut_multi_win2-2]..multi_win_lignes2[positionH_curseur+debut_multi_win2-1]
	    table.remove(multi_win_lignes2, positionH_curseur+debut_multi_win2-1)
	    ycurseur = ycurseur -10
	    n_lignes_win2=n_lignes_win2-1
	 elseif xcurseur==0 then
	 else
	    enleve_debut = string.sub(texte,(xcurseur/8) + 1)
	    enleve_fond = string.sub(texte,0,string.len(texte) - string.len(enleve_debut) - 1)
	    tout = enleve_fond .. enleve_debut
	    multi_win_lignes2[positionH_curseur+debut_multi_win2-1] = tout
	    xcurseur = xcurseur - 8
	 end
   end
end
 
while done_principal == false do
   pad = Controls.read()
   screen:clear()
   screen:blit(0,0,principal,0,0,480,272)
   screen:print(5,32,multi_win_nom1,noir)
   screen:print(245,32,multi_win_nom2,noir)
   if multi_win_nb == 1 then
	 screen:print(5,32,multi_win_nom1,rouge)
   else
	 screen:print(245,32,multi_win_nom2,rouge)
   end
   aff_text(debut)
   if aff_couleurs == true then 
	 if multi_win_nb == 1 then
	    syntaxe_win1()
	 else
	    syntaxe_win2()
	 end
   end
   if multi_win_nb == 1 then
	 cursor_win1()
   else
	 cursor_win2()   
   end
   menu()
   screen:blit(0,257,principal,0,257,480,15)
   if multi_win_nb == 1 then
	 screen:print(3,260,"Ln "..(positionH_curseur+debut_multi_win1-1).." / "..n_lignes_win1.." ; Col "..positionL_curseur,blanc)
	 screen:print(280,260,"Sel1 "..sel1_l_win1..":"..sel1_h_win1.." Sel2 "..sel2_l_win1..":"..sel2_h_win1,blanc)
   else
	 screen:print(3,260,"Ln "..(positionH_curseur+debut_multi_win2-1).." / "..n_lignes_win2.." ; Col "..positionL_curseur,blanc)
	 screen:print(280,260,"Sel1 "..sel1_l_win2..":"..sel1_h_win2.." Sel2 "..sel2_l_win2..":"..sel2_h_win2,blanc)
   end
   if pad:cross() and pad:left() then
	 multi_win_nb = 1
	 debut_multi_win1 = 1
	 xcurseur = 0
	 ycurseur = 49
   elseif pad:cross() and pad:right() then
	 multi_win_nb = 2
	 debut_multi_win2 = 1
	 xcurseur = 0
	 ycurseur = 49
   end
   if pad:select() and not oldpad:select() then
	 if multi_win_nb == 1 then
	    if sel1_h_win1 == 0 then
		  sel1_h_win1 = positionH_curseur+debut_multi_win1-1
		  sel1_l_win1 = positionL_curseur
	    elseif sel1_h_win1 ~= 0 and sel2_h_win1 == 0 and (sel1_h_win1 ~= positionH_curseur+debut_multi_win1-1 or sel1_l_win1 ~= positionL_curseur ) then
		  sel2_h_win1 = positionH_curseur+debut_multi_win1-1
		  sel2_l_win1 = positionL_curseur
	    elseif sel1_h_win1 ~= 0 and sel2_h_win1 ~= 0 then
		  sel2_h_win1 = 0
		  sel2_l_win1 = 0
		  sel1_h_win1 = 0
		  sel1_l_win1 = 0
	    end
	 else
	    if sel1_h_win2 == 0 then
		  sel1_h_win2 = positionH_curseur+debut_multi_win2-1
		  sel1_l_win2 = positionL_curseur
	    elseif sel1_h_win2 ~= 0 and sel2_h_win2 == 0 and (sel1_h_win2 ~= positionH_curseur+debut_multi_win2-1 or sel1_l_win2 ~= positionL_curseur ) then
		  sel2_h_win2 = positionH_curseur+debut_multi_win2-1
		  sel2_l_win2 = positionL_curseur
	    elseif sel1_h_win2 ~= 0 and sel2_h_win2 ~= 0 then
		  sel2_h_win2 = 0
		  sel2_l_win2 = 0
		  sel1_h_win2 = 0
		  sel1_l_win2 = 0
	    end
	 end
   end
   if pad:r() then
	  if pad:left() and aff_clavier == true and clavier_x > 0 then clavier_x = clavier_x - 1 end
	  if pad:right() and aff_clavier == true and clavier_x < 323 then clavier_x = clavier_x + 1 end
	  if pad:up() and not oldpad:up() then
		if multi_win_nb == 1 then
		   if debut_multi_win1-21 > 1 then 
			 debut_multi_win1 = debut_multi_win1 - 21
		   end
		else
		   if debut_multi_win2-21 > 1 then 
			 debut_multi_win2 = debut_multi_win2 - 21
		   end
		end
	  end
	  if pad:down() and not oldpad:down() then
		if multi_win_nb == 1 and debut_multi_win1 + 21 < n_lignes_win1 then
		   debut_multi_win1 = debut_multi_win1 + 21
		elseif multi_win_nb == 2 and debut_multi_win2 + 21 < n_lignes_win2 then
		   debut_multi_win2 = debut_multi_win2 + 21
		end
	  end
	  if pad:square() and aff_clavier == false then
		effacer()
	  end
   end
   if pad:circle() and oldpad:circle() ~= pad:circle() and aff_clavier == false then
	 if multi_win_nb == 1 then
		enleve_debut = string.sub(multi_win_lignes1[positionH_curseur+debut_multi_win1-1],(xcurseur/8) + 1)
		enleve_fin = string.sub(multi_win_lignes1[positionH_curseur+debut_multi_win1-1],0,string.len(multi_win_lignes1[positionH_curseur+debut_multi_win1-1])-string.len(enleve_debut))
		if xcurseur/8==positionH_curseur+debut_multi_win1-1 and enleve_debut~="" then
		   table.insert(multi_win_lignes1, positionH_curseur+debut_multi_win1-1, " ")
		   multi_win_lignes1[positionH_curseur+debut_multi_win1]=enleve_debut
		   multi_win_lignes1[positionH_curseur+debut_multi_win1-1]=" "
		   if i_defilement_horizontal_win1==1 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
		   elseif i_defilement_horizontal_win1==2 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
		   elseif i_defilement_horizontal_win1==3 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne2, positionH_curseur+debut_multi_win1-1, " ")
			elseif i_defilement_horizontal_win1==4 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne2, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne3, positionH_curseur+debut_multi_win1-1, " ")
		   end
		   ycurseur = ycurseur +10
		   xcurseur = 0
		   n_lignes_win1=n_lignes_win1+1
		elseif string.len(multi_win_lignes1[positionH_curseur+debut_multi_win1-1])==xcurseur/8 then
		   table.insert(multi_win_lignes1, positionH_curseur+debut_multi_win1, "")
		   if i_defilement_horizontal_win1==1 then
			  table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1, "")
		   elseif i_defilement_horizontal_win1==2 then
			  table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1, "")
			  table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1, "")
		   elseif i_defilement_horizontal_win1==3 then
			  table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1, "")
			  table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1, "")
			  table.insert(multi_win1_sauv_ligne2, positionH_curseur+debut_multi_win1, "")
		    elseif i_defilement_horizontal_win1==4 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1, " ")
			 table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1, " ")
			 table.insert(multi_win1_sauv_ligne2, positionH_curseur+debut_multi_win1, " ")
			 table.insert(multi_win1_sauv_ligne3, positionH_curseur+debut_multi_win1, " ")
		   end
		   ycurseur = ycurseur +10
		   xcurseur = 0
		   n_lignes_win1=n_lignes_win1+1
		elseif enleve_debut~="" then
		   table.insert(multi_win_lignes1, positionH_curseur+debut_multi_win1-1, " ")
		   multi_win_lignes1[positionH_curseur+debut_multi_win1]=enleve_debut
		   multi_win_lignes1[positionH_curseur+debut_multi_win1-1]=enleve_fin
		   if i_defilement_horizontal_win1==1 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
		   elseif i_defilement_horizontal_win1==2 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
			elseif i_defilement_horizontal_win1==3 then
			  table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			  table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
			  table.insert(multi_win1_sauv_ligne2, positionH_curseur+debut_multi_win1-1, " ")
		    elseif i_defilement_horizontal_win1==4 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne2, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne3, positionH_curseur+debut_multi_win1-1, " ")
		   end
		   ycurseur = ycurseur +10
		   xcurseur = 0
		   n_lignes_win1=n_lignes_win1+1
		else
		   table.insert(multi_win_lignes1, positionH_curseur+debut_multi_win1-1, " ")
		   if i_defilement_horizontal_win1==1 then
			  table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
		   elseif i_defilement_horizontal_win1==2 then
			  table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			  table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
		   elseif i_defilement_horizontal_win1==3 then
			  table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			  table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
			  table.insert(multi_win1_sauv_ligne2, positionH_curseur+debut_multi_win1-1, " ")
		    elseif i_defilement_horizontal_win1==4 then
			 table.insert(multi_win1_sauv_ligne, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne1, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne2, positionH_curseur+debut_multi_win1-1, " ")
			 table.insert(multi_win1_sauv_ligne3, positionH_curseur+debut_multi_win1-1, " ")
		   end
		   ycurseur = ycurseur +10
		   xcurseur = 0
		   n_lignes_win1=n_lignes_win1+1
		end
	  else
		enleve_debut = string.sub(multi_win_lignes2[positionH_curseur+debut_multi_win2-1],(xcurseur/8) + 1)
		enleve_fin = string.sub(multi_win_lignes2[positionH_curseur+debut_multi_win2-1],0,string.len(multi_win_lignes2[positionH_curseur+debut_multi_win2-1])-string.len(enleve_debut))
		if xcurseur/8==positionH_curseur+debut_multi_win2-1 and enleve_debut~="" then
		   table.insert(multi_win_lignes2, positionH_curseur+debut_multi_win2-1, " ")
		   multi_win_lignes2[positionH_curseur+debut_multi_win2]=enleve_debut
		   multi_win_lignes2[positionH_curseur+debut_multi_win2-1]=" "
		   if i_defilement_horizontal_win2==1 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
		   elseif i_defilement_horizontal_win2==2 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
		   elseif i_defilement_horizontal_win2==3 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne2, positionH_curseur+debut_multi_win2-1, " ")
			elseif i_defilement_horizontal_win2==4 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne2, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne3, positionH_curseur+debut_multi_win2-1, " ")
		   end
		   ycurseur = ycurseur +10
		   xcurseur = 0
		   n_lignes_win2=n_lignes_win2+1
		elseif string.len(multi_win_lignes2[positionH_curseur+debut_multi_win2-1])==xcurseur/8 then
		   table.insert(multi_win_lignes2, positionH_curseur+debut_multi_win2, "")
		   if i_defilement_horizontal_win2==1 then
			  table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2, "")
		   elseif i_defilement_horizontal_win2==2 then
			  table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2, "")
			  table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2, "")
		   elseif i_defilement_horizontal_win2==3 then
			  table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2, "")
			  table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2, "")
			  table.insert(multi_win2_sauv_ligne2, positionH_curseur+debut_multi_win2, "")
		    elseif i_defilement_horizontal_win2==4 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2, " ")
			 table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2, " ")
			 table.insert(multi_win2_sauv_ligne2, positionH_curseur+debut_multi_win2, " ")
			 table.insert(multi_win2_sauv_ligne3, positionH_curseur+debut_multi_win2, " ")
		   end
		   ycurseur = ycurseur +10
		   xcurseur = 0
		   n_lignes_win2=n_lignes_win2+1
		elseif enleve_debut~="" then
		   table.insert(multi_win_lignes2, positionH_curseur+debut_multi_win2-1, " ")
		   multi_win_lignes2[positionH_curseur+debut_multi_win2]=enleve_debut
		   multi_win_lignes2[positionH_curseur+debut_multi_win2-1]=enleve_fin
		   if i_defilement_horizontal_win2==1 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
		   elseif i_defilement_horizontal_win2==2 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
			elseif i_defilement_horizontal_win2==3 then
			  table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			  table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
			  table.insert(multi_win2_sauv_ligne2, positionH_curseur+debut_multi_win2-1, " ")
		    elseif i_defilement_horizontal_win2==4 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne2, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne3, positionH_curseur+debut_multi_win2-1, " ")
		   end
		   ycurseur = ycurseur +10
		   xcurseur = 0
		   n_lignes_win2=n_lignes_win2+1
		else
		   table.insert(multi_win_lignes2, positionH_curseur+debut_multi_win2-1, " ")
		   if i_defilement_horizontal_win2==1 then
			  table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
		   elseif i_defilement_horizontal_win2==2 then
			  table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			  table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
		   elseif i_defilement_horizontal_win2==3 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne2, positionH_curseur+debut_multi_win2-1, " ")
		    elseif i_defilement_horizontal_win2==4 then
			 table.insert(multi_win2_sauv_ligne, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne1, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne2, positionH_curseur+debut_multi_win2-1, " ")
			 table.insert(multi_win2_sauv_ligne3, positionH_curseur+debut_multi_win2-1, " ")
		   end
		   ycurseur = ycurseur +10
		   xcurseur = 0
		   n_lignes_win2=n_lignes_win2+1
		end
	  end
   end
   if pad:square() and not oldpad:square() and positionL_curseur ~= 0 and aff_clavier == false then
	  effacer()
   end
   if aff_clavier == true then aff_clavier_() end
   if pad:start() and not oldpad:start() and aff_clavier == false then
	 aff_clavier = true
   elseif pad:start() and not oldpad:start() and aff_clavier == true then
	 aff_clavier = false
   end
   if pad:triangle() and aff_clavier==false then mp3() end
   screen.waitVblankStart()
   screen.flip()
   oldpad = pad
end
