Skip to content

Commit

Permalink
Made keyboard.lua use a configuration file
Browse files Browse the repository at this point in the history
Thus removing the need to edit it directly as an user
  • Loading branch information
Neil Zeke Cecchini authored and Neil Zeke Cecchini committed Apr 2, 2016
1 parent eae356c commit c687efc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 49 deletions.
40 changes: 40 additions & 0 deletions sdcard/3ds/ctruLua/config/keyboard.cfg
@@ -0,0 +1,40 @@
keyWidth, keyHeight = 25, 25

layout = {
["default"] = {
{ "&", "é", "\"", "'", "(", "-", "è", "_", "ç", "à", ")", "=", "Bks" },
{ "a", "z", "e", "r", "t", "y", "u", "i", "o", "p", "^", "$", "Ent" },
{ "q", "s", "d", "f", "g", "h", "j", "k", "l", "m", "ù", "*", "Ent" },
{ "Shift", "<", "w", "x", "c", "v", "b", "n", ",", ";", ":", "!", "Tab" },
{ "SLck", ">", "+", "/", " ", " ", " ", " ", " ", "{", "}", ".", "Sym" }
},
["Shift"] = {
{ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "°", "+", "Bks" },
{ "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "¨", "£", "Ent" },
{ "Q", "S", "D", "F", "G", "H", "J", "K", "L", "M", "%", "µ", "Ent" },
{ "Shift", ">", "W", "X", "C", "V", "B", "N", "?", ".", "/", "§", "Tab" },
{ "SLck", "~", "#", "[", " ", " ", " ", " ", " ", "]", "|", "@", "Sym" }
},
["Sym"] = {
{ "²", "~", "#", "{", "[", "|", "`", "\\", "^", "@", "]", "}", "Bks" },
{ "a", "z", "€", "r", "t", "y", "u", "i", "o", "p", "", "¤", "Ent" },
{ "q", "s", "d", "f", "g", "h", "j", "k", "l", "m", "", "", "Ent" },
{ "Shift", "", "w", "x", "c", "v", "b", "n", "", "", "", "", "Tab" },
{ "SLck", "", "", "", " ", " ", " ", " ", " ", "", "", "", "Sym" }
},
}
alias = {
["Tab"] = "\t",
["Ent"] = "\n",
["Bks"] = "\b"
}
sticky = {
["SLck"] = "Shift"
}
keys = {
["l"] = "Shift",
["r"] = "Shift"
}
66 changes: 17 additions & 49 deletions sdcard/3ds/ctruLua/libs/keyboard.lua
@@ -1,44 +1,12 @@
local ctr = require("ctr")
local hid = require("ctr.hid")
local gfx = require("ctr.gfx")
local hex = gfx.color.hex

-- Options
local keyWidth, keyHeight = 25, 25
local layout = {
["default"] = {
{ "&", "é", "\"", "'", "(", "-", "è", "_", "ç", "à", ")", "=", "Back" },
{ "a", "z", "e", "r", "t", "y", "u", "i", "o", "p", "^", "$", "Enter" },
{ "q", "s", "d", "f", "g", "h", "j", "k", "l", "m", "ù", "*", "Enter" },
{ "Shift", "<", "w", "x", "c", "v", "b", "n", ",", ";", ":", "!", "Tab" },
{ "CpLck", ">", "+", "/", " ", " ", " ", " ", " ", "{", "}", ".", "AltGr" }
},
["Shift"] = {
{ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "°", "+", "Back" },
{ "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "¨", "£", "Enter" },
{ "Q", "S", "D", "F", "G", "H", "J", "K", "L", "M", "%", "µ", "Enter" },
{ "Shift", ">", "W", "X", "C", "V", "B", "N", "?", ".", "/", "§", "Tab" },
{ "CpLck", "~", "#", "[", " ", " ", " ", " ", " ", "]", "|", "@", "AltGr" }
},
["AltGr"] = {
{ "²", "~", "#", "{", "[", "|", "`", "\\", "^", "@", "]", "}", "Back" },
{ "a", "z", "", "r", "t", "y", "u", "i", "o", "p", "", "¤", "Enter" },
{ "q", "s", "d", "f", "g", "h", "j", "k", "l", "m", "", "", "Enter" },
{ "Shift", "", "w", "x", "c", "v", "b", "n", "", "", "", "", "Tab" },
{ "CpLck", "", "", "", " ", " ", " ", " ", " ", "", "", "", "AltGr" }
},
}
local alias = {
["Tab"] = "\t",
["Enter"] = "\n",
["Back"] = "BACK"
}
local sticky = {
["CpLck"] = "Shift"
}
local keys = {
["l"] = "Shift",
["r"] = "Shift"
}

local config = {}
loadfile(ctr.root .. "config/keyboard.cfg", nil, config)()

-- Variables
local currentModifier = { "default", "sticky" }
Expand All @@ -51,35 +19,35 @@ return {
local xTouch, yTouch
if hidKeys.down.touch then xTouch, yTouch = hid.touch() end

for key, modifier in pairs(keys) do
for key, modifier in pairs(config.keys) do
if hidKeys.down[key] then
currentModifier = { modifier, "key" }
elseif hidKeys.up[key] and currentModifier[2] == "key" and currentModifier[1] == modifier then
currentModifier = { "default", "sticky" }
end
end

for row, rowKeys in pairs(layout[currentModifier[1]]) do
for row, rowKeys in pairs(config.layout[currentModifier[1]]) do
for column, key in pairs(rowKeys) do
local xKey, yKey = x + (column-1)*(keyWidth-1), y + (row-1)*(keyHeight-1)
local xKey, yKey = x + (column-1)*(config.keyWidth-1), y + (row-1)*(config.keyHeight-1)

gfx.rectangle(xKey, yKey, keyWidth, keyHeight, 0, hex(0xFFFFFFFF))
gfx.rectangle(xKey + 1, yKey + 1, keyWidth - 2, keyHeight - 2, 0, hex(0x000000FF))
gfx.rectangle(xKey, yKey, config.keyWidth, config.keyHeight, 0, hex(0xFFFFFFFF))
gfx.rectangle(xKey + 1, yKey + 1, config.keyWidth - 2, config.keyHeight - 2, 0, hex(0x000000FF))
gfx.text(xKey + 2, yKey + 2, key)

if xTouch then
if xTouch > xKey and xTouch < xKey + keyWidth then
if yTouch > yKey and yTouch < yKey + keyHeight then
gfx.rectangle(xKey, yKey, keyWidth, keyHeight, 0, hex(0xDDFFFFFF))
if xTouch > xKey and xTouch < xKey + config.keyWidth then
if yTouch > yKey and yTouch < yKey + config.keyHeight then
gfx.rectangle(xKey, yKey, config.keyWidth, config.keyHeight, 0, hex(0xDDFFFFFF))

local k = alias[key] or key
if sticky[k] and layout[sticky[k]] then
if currentModifier[1] == sticky[k] and currentModifier[2] == "sticky" then
local k = config.alias[key] or key
if config.sticky[k] and config.layout[config.sticky[k]] then
if currentModifier[1] == config.sticky[k] and currentModifier[2] == "sticky" then
currentModifier = { "default", "sticky" }
else
currentModifier = { sticky[k], "sticky" }
currentModifier = { config.sticky[k], "sticky" }
end
elseif layout[k] then
elseif config.layout[k] then
if currentModifier[1] == k and currentModifier[2] == "normal" then
currentModifier = { "default", "sticky" }
else
Expand Down

0 comments on commit c687efc

Please sign in to comment.