keyIsDown(k);
Check if a keyboard key is pressed, returns true
if key is down and returns false
if it's not
Arguments
k
The keyboard key to check as a key global, or a stringReturns
boolean
Whether or not the key is down-- Use a string
if (keyIsDown('a')) then
-- key 'a' is down
end
-- use a global
if (keyIsDown(LEFT_ARROW)) then
-- left arrow is down
end
keyPressed(key, keyCode);
EventCalled whenever a key is pressed.
Arguments
key
The pressed key as a string, is nil if glfw cannot find a name for the key.keyCode
The pressed key as a key codefunction setup()
createWindow(200, 200);
background('purple');
text('Press any key', 10, 40);
end
-- no draw
function draw() return end
function keyPressed(key, keyCode)
print(key, keyCode);
background('purple');
if key ~= nil then
text('Pressed: ' .. key, 10, 40);
end
end
Output
keyReleased(key, keyCode);
EventCalled whenever a key is released.
Arguments
key
The released key as a string, is nil if glfw cannot find a name for the keykeyCode
The released key as a key codefunction setup()
createWindow(200, 200);
background('purple');
text('Release any key', 10, 40);
end
-- no draw
function draw() return end
function keyReleased(key, keyCode)
print(key, keyCode);
background('purple');
if key ~= nil then
text('Released: ' .. key, 10, 40);
end
end
Output
keyHeld(key, keyCode);
EventCalled whenever a key is held down.
Arguments
key
The held key as a string, is nil if glfw cannot find a name for the keykeyCode
The held key as a key codefunction setup()
createWindow(200, 200);
background('purple');
text('Hold any key', 10, 40);
end
-- no draw
function draw() return end
function keyHeld(key, keyCode)
print(key, keyCode);
background('purple');
if key ~= nil then
text('Held key: ' .. key, 10, 40);
end
end
Output