Difference between revisions of "Getkey"

From OpenEUO
Jump to: navigation, search
m
m
Line 6: Line 6:
 
   local keys = {'ESC', 'BACK', 'TAB', 'ENTER', 'CAPS', 'SPACE', 'PGDN', 'PGUP', 'END', 'HOME',
 
   local keys = {'ESC', 'BACK', 'TAB', 'ENTER', 'CAPS', 'SPACE', 'PGDN', 'PGUP', 'END', 'HOME',
 
     'LEFT', 'RIGHT', 'UP', 'DOWN', 'INS', 'DEL', 'NUM', 'SCROLL', 'CTRL', 'ALT', 'SHIFT'}
 
     'LEFT', 'RIGHT', 'UP', 'DOWN', 'INS', 'DEL', 'NUM', 'SCROLL', 'CTRL', 'ALT', 'SHIFT'}
 +
  for i = 1,12,1 do
 +
    table.insert(keys,'F'..tostring(i))
 +
  end
 
   while true do
 
   while true do
 
     for i = 1,#keys,1 do
 
     for i = 1,#keys,1 do

Revision as of 18:20, 15 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, SCROLL, CTRL, ALT, or SHIFT.

Warning: since getkey is based on GetAsyncKeyState, this function will register a currently depressed key regardless of what application is in the foreground.

 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))
 end
 while true do
   for i = 1,#keys,1 do
     if getkey(keys[i]) then print(keys[i]) wait(10) end
   end
 end

Getmouse