local function _handleSpecial(self, key)
for keyname,methodName in ipairs({ backspace='Backspace', return='Return', left='Left', right='Right', up='Up', down='Down' }) do
if key == keyname then
self[methodName](self)
return true
end
end
return false
end
function goo.textinput:keypressed(key,unicode)
if not self.focus then return false end
if not _handleSpecial(self, key) and unicode ~= 0 and unicode < 1000 then self:keyText(key,unicode) end
if self.onKeypressed then self:onKeypressed( key, unicode ) end
return true
end
function love.keypressed(k,u)
if textIn and u then --this is for text input
if k == "backspace" or k == "delete" and string.len(textInput) > 0then
textInput = string.sub(textInput,1,string.len(textInput) - 1)
elseif string.len(k) == 1 then
textInput = textInput..string.char(u)
end
else
--stuff unrelated to text input
I'm pretty sure I got at least part of it off the forum somewhere... I can't remember but it seems to work perfectly fine.
Readability leads to understanding, understanding leads to separation of concepts, separation of concepts leads to good efficiency.
Lack of readability is the path of the Dark Side. Lack of readability leads to fear, fear leads to anger, anger leads to hate, hate leads ... to suffering.
If you can't read your code, your more likely to make awful mistakes, the kind that leads to many, many bugs. I made this awful mistake with Space Attackers. Maybe I should post it after all, as a lesson.
function normaltyping(currentstring,key)
if key=="backspace" then --backspace logic
if #currentstring>1 then
currentstring=string.sub(currentstring,1,#currentstring-1)
else
currentstring=""
end
elseif key>="a" and key<="z" then --letters
if love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift") then --uppercase
currentstring=currentstring..string.upper(key)
else
currentstring=currentstring..key --lowercase
end
elseif key>="0" and key<="9" then --numbers
currentstring=currentstring..key
elseif key==" " then --spaces
currentstring=currentstring..key
end
return currentstring
end
For whatever reason, though, all of the keys are getting added to the string.