is_key_down Function #

Function Signature:

is_key_down(key)

Description: Checks if a specific key or button is currently pressed down.

Parameters:

  • key: (Type: Integer) The key or button to check. It should be one of the defined constants or values from the Keys table.

Keys Table:

  • Keys.A = 65 -- A key
  • Keys.B = 66 -- B key
  • Keys.C = 67 -- C key
  • Keys.D = 68 -- D key
  • Keys.E = 69 -- E key
  • Keys.F = 70 -- F key
  • Keys.G = 71 -- G key
  • Keys.H = 72 -- H key
  • Keys.I = 73 -- I key
  • Keys.J = 74 -- J key
  • Keys.K = 75 -- K key
  • Keys.L = 76 -- L key
  • Keys.M = 77 -- M key
  • Keys.N = 78 -- N key
  • Keys.O = 79 -- O key
  • Keys.P = 80 -- P key
  • Keys.Q = 81 -- Q key
  • Keys.R = 82 -- R key
  • Keys.S = 83 -- S key
  • Keys.T = 84 -- T key
  • Keys.U = 85 -- U key
  • Keys.V = 86 -- V key
  • Keys.W = 87 -- W key
  • Keys.X = 88 -- X key
  • Keys.Y = 89 -- Y key
  • Keys.Z = 90 -- Z key

Returns:

  • Boolean: Returns true if the specified key or button is currently pressed down, false otherwise.

Usage Example:

-- Check if the 'A' key is pressed down
if is_key_down(Keys.A) then
    print("The 'A' key is currently pressed.")
else
    print("The 'A' key is not pressed.")
end

-- Check if the 'W' key is pressed down
if is_key_down(Keys.W) then
    print("The 'W' key is currently pressed.")
else
    print("The 'W' key is not pressed.")
end

Notes:

  • The key parameter can be an input constant or a value from the Keys table.
  • This function is useful for real-time input checking to determine if specific keys or buttons are actively pressed.
  • Combine with other input checks or conditions to create responsive game controls or automation scripts.