Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
|
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.
|