View unanswered posts | View active topics It is currently Sat Jun 06, 2020 11:56 pm

Reply to topic  [ 2 posts ] 
 tokey function 
Author Message
User avatar

Joined: Tue Nov 17, 2009 7:38 pm
Posts: 909
Location: France
Reply with quote
Post tokey function

This is a little function I made that could be useful to anyone making things that are triggered by pressing a key: it automatically converts the key to its number, sparing you the inconvienience of having to go through the key list and making it easier to modify. So here it is:
function tokey(n)
   local KeyTable = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","num0","num1","num2","num3","num4","num5","num6","num7","num8","num9",".",".",".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","back","tab","enter",".",".",".",".","<",".",".",".","space","insert","del","home","end","pageup","pagedown","arrowleft","arrowright","arrowup","arrowdown"};
   local i = 1;
   while i <= 85 do
      if tostring(n):lower() == KeyTable[i] then
         i = i+1;
   return 0;

Here is an example of how it works:

print( tokey('s') );

Feel free to use it and modify it as you like.

Thu Oct 27, 2011 12:47 pm
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: tokey function
I like this, it's a good idea. We need more time-conserving functions like this one.

Thu Oct 27, 2011 3:29 pm
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.015s | 15 Queries | GZIP : Off ]