Difference between revisions of "Getkey"
m (added NUM0-NUM9) |
|||
(8 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
local bpressed = getkey(str) | local bpressed = getkey(str) | ||
− | Returns a boolean based upon whether a key or key combination as specified by the string str is depressed or not. The key-specifier string str can contain A-Z, 0-9, F1-F12 and ESC, BACK, TAB, ENTER, | + | Returns a boolean based upon whether a key or key combination as specified by the string str is depressed or not. The key-specifier string str can contain A-Z, 0-9, F1-F12 and ESC, BACK, TAB, ENTER, CAPS, SPACE, PGDN, PGUP, END, HOME, LEFT, RIGHT, UP, DOWN, INS, DEL, NUM, CTRL, ALT, or SHIFT. If numlock is on, one can also detect NUM0-NUM9. Due to differences in operating system versions, keyboard drivers, and language settings, some keys may not be detectable on all systems or may be misidentified. Current list of known problem keys: PRNSCR, PAUSE, SCROLL. The following script can be used to test functionality on individual systems. |
+ | |||
+ | local keys = {'ESC', 'BACK', 'TAB', 'ENTER', 'CAPS', 'SPACE', 'PGDN', 'PGUP', 'END', 'HOME', | ||
+ | 'LEFT', 'RIGHT', 'UP', 'DOWN', 'INS', 'DEL', 'NUM', 'SCROLL', 'CTRL', 'ALT', 'SHIFT'} | ||
+ | for i = 1,12,1 do | ||
+ | table.insert(keys,'F'..tostring(i)) | ||
+ | if i < 11 then | ||
+ | table.insert(keys,'NUM'..tostring(i-1)) | ||
+ | end | ||
+ | end | ||
+ | while true do | ||
+ | for i = 1,#keys,1 do | ||
+ | if getkey(keys[i]) then print(keys[i]) wait(10) end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | Warning: this function will register a currently depressed key regardless of what application is in the foreground. | ||
+ | |||
+ | [http://msdn.microsoft.com/en-us/library/ms646293%28VS.85%29.aspx GetAsyncKeyState] | ||
+ | |||
+ | [[Getmouse]] |
Latest revision as of 11:09, 21 July 2012
local bpressed = getkey(str)
Returns a boolean based upon whether a key or key combination as specified by the string str is depressed or not. The key-specifier string str can contain A-Z, 0-9, F1-F12 and ESC, BACK, TAB, ENTER, CAPS, SPACE, PGDN, PGUP, END, HOME, LEFT, RIGHT, UP, DOWN, INS, DEL, NUM, CTRL, ALT, or SHIFT. If numlock is on, one can also detect NUM0-NUM9. Due to differences in operating system versions, keyboard drivers, and language settings, some keys may not be detectable on all systems or may be misidentified. Current list of known problem keys: PRNSCR, PAUSE, SCROLL. The following script can be used to test functionality on individual systems.
local keys = {'ESC', 'BACK', 'TAB', 'ENTER', 'CAPS', 'SPACE', 'PGDN', 'PGUP', 'END', 'HOME', 'LEFT', 'RIGHT', 'UP', 'DOWN', 'INS', 'DEL', 'NUM', 'SCROLL', 'CTRL', 'ALT', 'SHIFT'} for i = 1,12,1 do table.insert(keys,'F'..tostring(i)) if i < 11 then table.insert(keys,'NUM'..tostring(i-1)) end end while true do for i = 1,#keys,1 do if getkey(keys[i]) then print(keys[i]) wait(10) end end end
Warning: this function will register a currently depressed key regardless of what application is in the foreground.