Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initialisation du terminal ou monitor
- local monitor = peripheral.find("monitor") or term -- Utilise un monitor ou le terminal par défaut
- -- Configuration de base
- monitor.setTextScale(1) -- Ajuste la taille pour un monitor
- monitor.setBackgroundColor(colors.black) -- Fond noir par défaut
- monitor.setTextColor(colors.white) -- Texte blanc
- monitor.clear()
- -- Tableau pour stocker les chiffres du pavé et leurs positions
- local keypad = {}
- local rows, cols = 2, 5 -- Position initiale du pavé (ligne, colonne)
- -- Fonction pour dessiner un pavé numérique
- local function drawKeypad()
- local keys = {
- "7", "8", "9",
- "4", "5", "6",
- "1", "2", "3",
- " ", "0", " " -- Espace pour correspondre au pavé
- }
- for i, key in ipairs(keys) do
- monitor.setCursorPos(cols, rows)
- monitor.write(key) -- Affiche chaque chiffre ou espace
- keypad[rows .. "," .. cols] = key -- Stocke le caractère et sa position
- cols = cols + 2 -- Avance d'une colonne
- if i % 3 == 0 then -- Nouvelle ligne après 3 chiffres
- cols = 5
- rows = rows + 1
- end
- end
- end
- -- Fonction pour colorer un chiffre cliqué
- local function highlightKey(x, y, color)
- local key = keypad[y .. "," .. x] -- Récupère le caractère basé sur la position
- if key and key ~= " " then -- Si c'est un chiffre (et pas un espace)
- local oldBg = monitor.getBackgroundColor() -- Sauvegarde l'ancienne couleur de fond
- monitor.setCursorPos(x, y)
- monitor.setBackgroundColor(color) -- Change le fond
- monitor.write(key) -- Réécrit le caractère avec la nouvelle couleur de fond
- monitor.setBackgroundColor(oldBg) -- Réinitialise le fond
- end
- end
- -- Dessine le pavé numérique initial
- drawKeypad()
- -- Boucle principale pour gérer les clics
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch") -- Événement pour un clic sur monitor
- highlightKey(x, y, colors.green) -- Exemple : change en vert au clic
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement