Data Realms Fan Forums http://45.55.195.193/ |
|
tokey function http://45.55.195.193/viewtopic.php?f=73&t=25996 |
Page 1 of 1 |
Author: | Mehman [ Thu Oct 27, 2011 12:47 pm ] |
Post subject: | 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. |
Author: | Roast Veg [ Thu Oct 27, 2011 3:29 pm ] |
Post subject: | Re: tokey function |
I like this, it's a good idea. We need more time-conserving functions like this one. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |