I would like to hideKeyboard() when the user taps the keyboard’s “return” key, but I can’t find documentation for how it is defined by Codea. When I use print("Key pressed: " … key) the output is just a blank new line in the console. Any suggestions?
I believe (iPad not with me at the moment) that RETURN is a pre-defined value.
Sorry, that was clear as mud. What I meant to say was, I think you can do…
if key == RETURN then
Aha! Thanks guys! I was using quotes to wrap “RETURN” when it should not be in quotes because it is a pre-defined constant as you’ve both displayed. To add to this, I think while the current wiki is sufficient, it may be improved with a page for all of the pre-defined constants in one place. Like a reference for all the possible values of “key” in the Keyboard(key) callback function.
Hello @matthew. In respect of global variables used by the Codea API, the page on the Codea Wiki here may be of help.
. @matthew Here is something I wrote long ago. It shows the decimal and hex values for the displayable keys, but also shows the values for special keys. What I mean by special key are the extra keys that show when you hold your finger for awhile on a key. For instance, hold your finger on “y u i o p”. The are other keys that also do this. When you press return, it shows a decimal value of 10, but pressing backspace shows a value of nil. The return key uses the variable RETURN, and the backspace key uses BACKSPACE. Also, here is a list of Codea 1.5 functions, variables, and tables. http://twolivesleft.com/Codea/Talk/discussion/2211/codea-1-5-information#Item_1
-- Ascii chart and key values
supportedOrientations(PORTRAIT)
function setup()
displayMode(FULLSCREEN)
showKeyboard()
cval="char ="
dval="dec ="
hval="hex ="
end
function draw()
background(30,30,30)
textMode(CORNER)
text("ASCII CHART",200,950)
text("PRESS ANY KEY",600,950)
text(cval,600,900)
text(dval,600,850)
text(hval,600,800)
z=0
textMode(CENTER)
for y=1,16 do
for x=1,16 do
xx=20+x*30
yy=950-y*40
fill(255,0,0)
text(z,xx,yy)
fill(0,255,0)
text(string.char(z),xx,yy-20)
z = z + 1
end
end
-- re-show keyboard if hide keyboard key is pressed
if CurrentTouch.x > 650 and CurrentTouch.y < 100 then
showKeyboard()
end
end
function keyboard(key)
if string.byte(key) == nil then
cval="nil"
dval="nil"
hval="nil"
return
end
cval=string.format("char = %s",key)
dval=string.format("dec = %3d",string.byte(key))
hval=string.format("hex = %02X",string.byte(key))
end