View unanswered posts | View active topics It is currently Thu Apr 18, 2024 8:44 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
Hi,

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:
Code:
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
         return(i);
      else
         i = i+1;
      end
   end
   return 0;
end


Here is an example of how it works:

user:
print( tokey('s') );
computer:
PRINT: 19

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


Thu Oct 27, 2011 12:47 pm
Profile
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
Profile
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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.036s | 15 Queries | GZIP : Off ]