I now started working on putting it on a class, so that you could use multiple textboxes in the same screen etc, but that’ll take some time to finish
but does anyone know why the backspace button ‘slows’ down when deleting a few letters? like if i keep backspace held down, it deletes good, but suddenly it stops…
@stevon8ter Maybe this little example will explain your backspace problem. When you hold down the backspace key, characters start getting erased. After a few seconds, instead of characters getting erased, words get erased. When the keyboardBuffer is empty, the backspace key stops working unless you start to tap it character by character. So while the backspace key is removing characters, then words, you’re just removing characters. To see an example, key a bunch of words, then hold down the backspace key.
displayMode(FULLSCREEN)
function setup()
w=WIDTH/2
showKeyboard()
count=0
str=""
end
function draw()
background(40, 40, 50)
fill(255)
str=keyboardBuffer()
text("characters in keyboard buffer "..string.len(str),w,700)
text(str,w,650)
text("number of keys pressed "..count,w,600)
end
function keyboard(k)
if k==BACKSPACE then
count=count-1
else
count=count+1
end
end
Ok @dave1707 that makes sense, i didn’t know the keyboard in codea worked that way as well, but my way of working… it won’t allow using this method…
Tho I’m going to take a look at it closer, it could be that i’m mistaken
Too bad there isn’t a way of putting something into the buffer without having to type it…
hmmmm, or is there a way to block the default backspace function?
@stevon8ter I’m not sure if there’s a way around the backspace key other than not using it. One way you might be able to do this is to get the length of the string that’s in the keyboardBuffer(). Each time that length changes, delete that many characters. Whatever you key is in the keyboardBuffer until you hide the keyboard. One problem you’ll run into is when you move the cursor inthe middle of a line and key more words. When the backspace key starts deleting words, the size of the words that are deleted won’t correspond to the words where you moved the cursor. So you could be deleting parts of words.
yeah i get what you mean, also when hiding the keyboard as you say… there wouldn’t be anything in the buffer when calling the keyboard again, hmmmm, let me think…xp
Just one of my other ideas… what if i determine the location of the backspace button… and place my own, ‘invisible’ button on the same location…? tho i think codea doesn’t detect touches in the location the keyboard’s at…
I havent looked at the code yet but if you are displaying the keyboardBuffer why not just display your own string and when the backspace key is pressed remove the correct letter based on where the cursor is?
@JakAttak His problem is that when the backspace key is held down, after a few seconds it starts deleting whole words while he is only deleting characters. After the keyboard buffer is empty, it stops back spacing until you release the backspace key. Then it only deletes a character at a time each time the backspace key is hit and does nothing if it’s held down.
I can only think of 1 easy way… and that’s custom keyboard… tho that’s not as simple as it looks… xD
if only we were able to adjust the keyboardbuffer to our own strings… would make my program so much easyer
@stevon8ter: after 20 seconds I see the first issues…
1: When using emoji (which length is longer than 1 char) you cannot move the caret correctly anymore. Everything gets corrupt.
2: Text is tinted, which means emoji (and other possibly colored characters) get tinted too, which looks ugly…
3: Moving the caret, should be ONLY possible, when finger is over the text. For now you can drag everywhere on the screen and it gets dispatched anyway.
The whole project is super useful! Keep working on it! I just wanted to give you hints for improvements.
Don’t use the keyboardBuffer() function. Rather record each key press via the key() function and update an internal variable (for performance, it is better to use a table of characters than a string).
If you want your own keyboard, I have one. You can see it in use in the Hangman program that’s recently been bumped. I’m going through my library code uploading it to CC, this’ll be in the next batch I expect.
Could be, or it could be {'H', 'e', 'l', 'l', 'o', "\ ", 'H', 'o', ...}.
The point is that insertion and deletion from a table is far more efficient than from a string. And strings are a bit funny in lua: there is one copy of each string that is used and all others point to it. So the two ls in the above table are both pointers to a single l in lua’s memory. This has implications for string building and modifying. Every time you modify a string you actually create a whole new string, and the old one doesn’t go away until it is garbage collected. So if you create a string by adding one character at a time, say by doing: s = s .. k, then each time you create an entirely new string. So using tables avoids this. To convert to a string at the end, use table.concat().
Ok didn’t know that, I thought tables were going to make it harder, but the way you say it… it makes sense
And this will also solve the issue of emoji, since i don’t delete chars, but the complete thing
Hmmm well i still got a little difficulty, when typing emoji, the font color should be white… but that means that the only way to do it… would be to put the color to white… but that means you can’t use black or other color text