Difference between revisions of "on.charIn"

From Inspired-Lua Wiki
Jump to navigation Jump to search
Line 11: Line 11:
  
 
  function on.charIn(char)
 
  function on.charIn(char)
     if string.len(input) >= 25 then  -- Here, we set a 25 chars limit
+
     input = input..char  -- appending
        input = input..char  -- appending
+
    platform.window:invalidate()  -- refreshing the screen
        platform.window:invalidate()  -- refreshing the screen
 
    end
 
 
  end
 
  end
  
function on.backspaceKey()
 
    input = string.usub(input,0,string.len(input)-1)  -- deleting the last char (with unicode support)
 
    platform.window:invalidate()  -- refreshing the screen
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 11:53, 22 December 2011

on.charIn is an event that catches the user's keypresses on the keyboard.

Here's an example on how to use it :

 input = ""   -- the string that will contain the user's typed message

 function on.paint(gc)
     gc:drawString(input,5,5,"top")  -- drawing the current string on screen
 end

 function on.charIn(char)
     input = input..char   -- appending
     platform.window:invalidate()   -- refreshing the screen
 end

You can here find a more detailed tutorial on how to use it to create a text input function : http://www.inspired-lua.org/2011/12/how-to-have-a-nice-little-input-function-in-lua/