{"id":890,"date":"2014-12-14T19:30:03","date_gmt":"2014-12-14T18:30:03","guid":{"rendered":"https:\/\/www.customprotocol.com\/?post_type=it_programmation&amp;p=890"},"modified":"2014-12-14T19:30:03","modified_gmt":"2014-12-14T18:30:03","slug":"programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp","status":"publish","type":"it_programmation","link":"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/","title":{"rendered":"Programmer en Lua&nbsp;-&nbsp;D\u00e9butant&nbsp;-&nbsp;Cours n\u00b05&nbsp;: Les touches de la PSP"},"content":{"rendered":"<blockquote>\n<p><em>Vous visitez actuellement un de nos cours pour programmer en Lua. Pour voir la liste des cours disponibles sur le site,\u00a0<a title=\"Programmer en Lua\" href=\"https:\/\/www.customprotocol.com\/programmation\/dev-lua-programmer-en-lua\/\" target=\"_blank\" rel=\"noopener noreferrer\">cliquez ici<\/a>.<\/em><\/p>\n<\/blockquote>\n<p>Nous allons apprendre dans ce cours \u00e0 maitriser les touches de la PSP, ce qui va nous permettre de cr\u00e9er vos propres programmes de mani\u00e8re guid\u00e9 (bient\u00f4t dans un Travail Pratique). Nous n'en sommes pas encore l\u00e0, mais si vous pers\u00e9v\u00e9rez, je suis sur que vous allez y arriver sans probl\u00e8me, en suivant bien le cours que nous allons aborder&#8239;;)<\/p>\n<p>Tout d'abord, il va falloir stocker du texte, on pourrait cr\u00e9er des variables mais nous allons r\u00e9utiliser le cours d'avant pour pouvoir r\u00e9aliser notre programme. Nous allons donc utiliser des tables qui contiendront des informations par rapport \u00e0 la touche pour ensuite les afficher sur l'\u00e9cran de la PSP. Par exemple, je reste appuy\u00e9 sur la touche croix, donc ma PSP affichera que j'appuie sur la touche croix.<\/p>\n<p>Donc on cr\u00e9e une table contenant toutes les informations n\u00e9cessaires...<\/p>\n<pre class=\"lang:lua decode:true\" title=\"Etape 1\">table&nbsp;=&nbsp;{}--Cr\u00e9ation d'une table regroupant toutes les infos suivantes\ntable[1]&nbsp;=&nbsp;\"Appuie sur la touche Croix\"\ntable[2]&nbsp;=&nbsp;\"Appuie sur la touche Triangle\"\ntable[3]&nbsp;=&nbsp;\"Appuie sur la touche Carr\u00e9\"\ntable[4]&nbsp;=&nbsp;\"Appuie sur la touche Rond\"\ntable[5]&nbsp;=&nbsp;\"Appuie sur la touche Haut\"\ntable[6]&nbsp;=&nbsp;\"Appuie sur la touche Droite\"\ntable[7]&nbsp;=&nbsp;\"Appuie sur la touche Gauche\"\ntable[8]&nbsp;=&nbsp;\"Appuie sur la touche Bas\"\ntable[9]&nbsp;=&nbsp;\"Appuie sur la touche R\"\ntable[10]&nbsp;=&nbsp;\"Appuie sur la touche L\"\ntable[11]&nbsp;=&nbsp;\"Appuie sur la touche START\"\ntable[12]&nbsp;=&nbsp;\"Appuie sur la touche SELECT\"<\/pre>\n<p>\u00a0Nous n'aborderons pas le stick analogique qui sera abord\u00e9 dans un cours pour r\u00e9aliser un menu avec curseur.<\/p>\n<p>Tr\u00e8s bien maintenant nous pouvons mettre notre <strong>boucle while true do.<\/strong><\/p>\n<pre class=\"lang:lua decode:true \" title=\"Etape 2\">while true do<\/pre>\n<p>\u00a0Et nous allons rajouter ensuite la fonction suivante qui va permettre de lire les boutons qui sont actionn\u00e9s dans le programme \u00e0 chaque d\u00e9but de la boucle.<\/p>\n<pre class=\"lang:lua decode:true\" title=\"Etape 3\">buttons.read()--Lecture des touches actionn\u00e9es\n<\/pre>\n<p>Maintenant nous allons utiliser pour la premi\u00e8re fois <strong>une condition<\/strong>. Nous voulons afficher tel texte pour tel touche de la PSP, donc si je reste appuyer sur la touche croix alors j'affiche le texte \"Appuie sur la touche Croix\".<\/p>\n<p>Ce qui donnera en Lua&nbsp;:<\/p>\n<pre class=\"lang:lua decode:true \" title=\"Etape 4\">if buttons.held.cross then--Si je reste appuy\u00e9 sur la touche croix alors\n screen.print(5,10,table[1])--J'affiche le texte ad\u00e9quat\nend--Fin de la condition<\/pre>\n<p>Puis on fait la m\u00eame chose pour toute les touches de la PSP.<\/p>\n<pre class=\"lang:lua decode:true\" title=\"Etape 5\">if buttons.held.triangle then--Si je reste appuy\u00e9 sur la touche triangle alors\n  screen.print(5,20,table[2])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.square then--Si je reste appuy\u00e9 sur la touche carr\u00e9 alors\n  screen.print(5,30,table[3])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.circle then--Si je reste appuy\u00e9 sur la touche rond alors\n  screen.print(5,40,table[4])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.up then--Si je reste appuy\u00e9 sur la touche haut alors\n  screen.print(5,50,table[5])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.right then--Si je reste appuy\u00e9 sur la touche droite alors\n  screen.print(5,60,table[6])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.left then--Si je reste appuy\u00e9 sur la touche gauche alors\n  screen.print(5,70,table[7])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.down then--Si je reste appuy\u00e9 sur la touche bas alors\n  screen.print(5,80,table[8])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.r then--Si je reste appuy\u00e9 sur la touche R alors\n  screen.print(5,90,table[9])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.l then--Si je reste appuy\u00e9 sur la touche L alors\n  screen.print(5,100,table[10])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.start then--Si je reste appuy\u00e9 sur la touche Start alors\n  screen.print(5,110,table[11])--J'affiche le texte\nend--Fin de la condition\n\nif buttons.held.select then--Si je reste appuy\u00e9 sur la touche S\u00e9lect alors\n  screen.print(5,120,table[12])--J'affiche le texte\nend--Fin de la condition<\/pre>\n<p>Voil\u00e0 maintenant il ne reste plus qu'\u00e0 <strong>rafraichir l'\u00e9cran<\/strong> \u00e0 chaque fin de tour de notre boucle et fermer la <strong>boucle while true do.<\/strong><\/p>\n<pre class=\"lang:lua decode:true\" title=\"Etape 6\">screen.flip()--Rafraichissement de l'\u00e9cran\n\nend--Fin de la boucle<\/pre>\n<p>\u00a0Voil\u00e0 normalement vous devez obtenir ceci&nbsp;:<\/p>\n<p style=\"text-align: center;\">\u00a0<a href=\"https:\/\/www.customprotocol.com\/medias\/2014\/12\/screen-cours-5-debutant.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1008\" src=\"https:\/\/www.customprotocol.com\/medias\/2014\/12\/screen-cours-5-debutant-300x170.png\" alt=\"screen-cours-5-d\u00e9butant\" width=\"300\" height=\"170\" srcset=\"https:\/\/www.customprotocol.com\/medias\/2014\/12\/screen-cours-5-debutant-300x170.png 300w, https:\/\/www.customprotocol.com\/medias\/2014\/12\/screen-cours-5-debutant-370x210.png 370w, https:\/\/www.customprotocol.com\/medias\/2014\/12\/screen-cours-5-debutant-270x153.png 270w, https:\/\/www.customprotocol.com\/medias\/2014\/12\/screen-cours-5-debutant.png 480w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Voil\u00e0 le code en entier:<\/p>\n<pre class=\"lang:lua decode:true\" title=\"R\u00e9capitulons\">table&nbsp;=&nbsp;{}--Cr\u00e9ation d'une table regroupant toutes les infos suivantes\ntable[1]&nbsp;=&nbsp;\"Appuie sur la touche Croix\"\ntable[2]&nbsp;=&nbsp;\"Appuie sur la touche Triangle\"\ntable[3]&nbsp;=&nbsp;\"Appuie sur la touche Carr\u00e9\"\ntable[4]&nbsp;=&nbsp;\"Appuie sur la touche Rond\"\ntable[5]&nbsp;=&nbsp;\"Appuie sur la touche Haut\"\ntable[6]&nbsp;=&nbsp;\"Appuie sur la touche Droite\"\ntable[7]&nbsp;=&nbsp;\"Appuie sur la touche Gauche\"\ntable[8]&nbsp;=&nbsp;\"Appuie sur la touche Bas\"\ntable[9]&nbsp;=&nbsp;\"Appuie sur la touche R\"\ntable[10]&nbsp;=&nbsp;\"Appuie sur la touche L\"\ntable[11]&nbsp;=&nbsp;\"Appuie sur la touche START\"\ntable[12]&nbsp;=&nbsp;\"Appuie sur la touche SELECT\"\n\nwhile true do--D\u00e9but de la boucle\n\t\n\tbuttons.read()--Lecture des touches actionn\u00e9es\n\t\n\tif buttons.held.cross then--Si je reste appuy\u00e9 sur la touche croix alors\n\t\tscreen.print(5,10,table[1])--J'affiche le texte ad\u00e9quat\n\tend--Fin de la condition\n\t\n\tif buttons.held.triangle then--Si je reste appuy\u00e9 sur la touche triangle alors\n\t  screen.print(5,20,table[2])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.square then--Si je reste appuy\u00e9 sur la touche carr\u00e9 alors\n\t  screen.print(5,30,table[3])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.circle then--Si je reste appuy\u00e9 sur la touche rond alors\n\t  screen.print(5,40,table[4])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.up then--Si je reste appuy\u00e9 sur la touche haut alors\n\t  screen.print(5,50,table[5])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.right then--Si je reste appuy\u00e9 sur la touche droite alors\n\t  screen.print(5,60,table[6])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.left then--Si je reste appuy\u00e9 sur la touche gauche alors\n\t  screen.print(5,70,table[7])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.down then--Si je reste appuy\u00e9 sur la touche bas alors\n\t  screen.print(5,80,table[8])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.r then--Si je reste appuy\u00e9 sur la touche R alors\n\t  screen.print(5,90,table[9])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.l then--Si je reste appuy\u00e9 sur la touche L alors\n\t  screen.print(5,100,table[10])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.start then--Si je reste appuy\u00e9 sur la touche Start alors\n\t  screen.print(5,110,table[11])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tif buttons.held.select then--Si je reste appuy\u00e9 sur la touche S\u00e9lect alors\n\t  screen.print(5,120,table[12])--J'affiche le texte\n\tend--Fin de la condition\n\t\n\tscreen.flip()--Rafraichie l'\u00e9cran\n\t\nend--Fin de la boucle while\n\t\t<\/pre>\n<p>Maintenant que vous savez utiliser les touches de votre PSP, vous allez pouvoir commencer s\u00e9rieusement \u00e0 penser \u00e0 des projets mais pour cela, il faudra encore apprendre de nouvelle chose&nbsp;\ud83d\ude42\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un cours pour apprendre \u00e0 contr\u00f4ler les touches en Lua sur PSP.<\/p>\n","protected":false},"author":22,"featured_media":1009,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"footnotes":""},"categories":[577,454,581],"tags":[584,450],"programmation-categorie":[578,580],"class_list":["post-890","it_programmation","type-it_programmation","status-publish","format-standard","has-post-thumbnail","hentry","category-cours-lua","category-programmation","category-tutos-programmation","tag-controles-des-touches","tag-lua","programmation_categorie-cours-lua","programmation_categorie-tutos"],"yoast_head":"\n<title>Programmer en Lua \u2013 D\u00e9butant \u2013 Cours n\u00b05 : Les touches de la PSP - Custom Protocol<\/title>\n<meta name=\"description\" content=\"Un cours pour apprendre \u00e0 contr\u00f4ler les touches en Lua sur PSP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/\" \/>\n<meta property=\"og:locale\" content=\"fr_CA\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Programmer en Lua \u2013 D\u00e9butant \u2013 Cours n\u00b05 : Les touches de la PSP - Custom Protocol\" \/>\n<meta property=\"og:description\" content=\"Un cours pour apprendre \u00e0 contr\u00f4ler les touches en Lua sur PSP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/\" \/>\n<meta property=\"og:site_name\" content=\"Custom Protocol\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.customprotocol.com\/medias\/2014\/12\/imagealaune-lestouchescours.png\" \/>\n\t<meta property=\"og:image:width\" content=\"720\" \/>\n\t<meta property=\"og:image:height\" content=\"504\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimation du temps de lecture\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/\",\"url\":\"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/\",\"name\":\"Programmer en Lua \u2013 D\u00e9butant \u2013 Cours n\u00b05 : Les touches de la PSP - Custom Protocol\",\"isPartOf\":{\"@id\":\"https:\/\/www.customprotocol.com\/#website\"},\"datePublished\":\"2014-12-14T18:30:03+00:00\",\"dateModified\":\"2014-12-14T18:30:03+00:00\",\"description\":\"Un cours pour apprendre \u00e0 contr\u00f4ler les touches en Lua sur PSP.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/#breadcrumb\"},\"inLanguage\":\"fr-CA\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.customprotocol.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programmation\",\"item\":\"https:\/\/www.customprotocol.com\/programmation\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Programmer en Lua&nbsp;-&nbsp;D\u00e9butant&nbsp;-&nbsp;Cours n\u00b05&nbsp;: Les touches de la PSP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.customprotocol.com\/#website\",\"url\":\"https:\/\/www.customprotocol.com\/\",\"name\":\"Custom Protocol\",\"description\":\"Site d&#039;hack-tualit\u00e9 et de tutoriels sur la customisation de consoles et appareils (homebrews, plugins, \u00e9mulation...)\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.customprotocol.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"fr-CA\"}]}<\/script>\n","yoast_head_json":{"title":"Programmer en Lua \u2013 D\u00e9butant \u2013 Cours n\u00b05 : Les touches de la PSP - Custom Protocol","description":"Un cours pour apprendre \u00e0 contr\u00f4ler les touches en Lua sur PSP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/","og_locale":"fr_CA","og_type":"article","og_title":"Programmer en Lua \u2013 D\u00e9butant \u2013 Cours n\u00b05 : Les touches de la PSP - Custom Protocol","og_description":"Un cours pour apprendre \u00e0 contr\u00f4ler les touches en Lua sur PSP.","og_url":"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/","og_site_name":"Custom Protocol","og_image":[{"width":720,"height":504,"url":"https:\/\/www.customprotocol.com\/medias\/2014\/12\/imagealaune-lestouchescours.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Estimation du temps de lecture":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/","url":"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/","name":"Programmer en Lua \u2013 D\u00e9butant \u2013 Cours n\u00b05 : Les touches de la PSP - Custom Protocol","isPartOf":{"@id":"https:\/\/www.customprotocol.com\/#website"},"datePublished":"2014-12-14T18:30:03+00:00","dateModified":"2014-12-14T18:30:03+00:00","description":"Un cours pour apprendre \u00e0 contr\u00f4ler les touches en Lua sur PSP.","breadcrumb":{"@id":"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/#breadcrumb"},"inLanguage":"fr-CA","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.customprotocol.com\/programmation\/programmer-en-lua-debutant-cours-n5-les-touches-de-la-psp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.customprotocol.com\/"},{"@type":"ListItem","position":2,"name":"Programmation","item":"https:\/\/www.customprotocol.com\/programmation\/"},{"@type":"ListItem","position":3,"name":"Programmer en Lua&nbsp;-&nbsp;D\u00e9butant&nbsp;-&nbsp;Cours n\u00b05&nbsp;: Les touches de la PSP"}]},{"@type":"WebSite","@id":"https:\/\/www.customprotocol.com\/#website","url":"https:\/\/www.customprotocol.com\/","name":"Custom Protocol","description":"Site d&#039;hack-tualit\u00e9 et de tutoriels sur la customisation de consoles et appareils (homebrews, plugins, \u00e9mulation...)","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.customprotocol.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"fr-CA"}]}},"_links":{"self":[{"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/programmation\/890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/programmation"}],"about":[{"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/types\/it_programmation"}],"author":[{"embeddable":true,"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/comments?post=890"}],"version-history":[{"count":0,"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/programmation\/890\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/media\/1009"}],"wp:attachment":[{"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/media?parent=890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/categories?post=890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/tags?post=890"},{"taxonomy":"programmation_categorie","embeddable":true,"href":"https:\/\/www.customprotocol.com\/api\/wp\/v2\/programmation-categorie?post=890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}