Difference between revisions of "Lua:isKeyPressed"

From Cheat Engine
Jump to navigation Jump to search
m
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' isKeyPressed(''key'')
+
'''function''' isKeyPressed(''Key'') ''':''' Boolean
  
Returns true if the given keycode is valid and pressed down
+
Returns true if the specified key is currently pressed.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|key
+
|Key
|[[Virtual-Key Code]]
+
|Integer or [[Virtual Key Codes]]
|The keycode for the key to test
+
|The virtual key code of the key to check (e.g., <code>VK_F1</code>, <code>VK_SHIFT</code>).
 
|}
 
|}
  
 +
===Returns===
 +
Boolean — true if the key is pressed, false otherwise.
  
{{LuaSeeAlso}}
+
===Examples===
* [[Virtual-Key Code]]
+
<pre>
 +
if isKeyPressed(VK_SPACE) then
 +
  print("Spacebar is currently pressed!")
 +
end
 +
 
 +
if isKeyPressed(VK_LSHIFT) then
 +
  print("Left Shift is pressed")
 +
end
 +
</pre>
 +
 
 +
== See also ==
 +
* [[keyDown]]
 +
* [[keyUp]]
 +
* [[doKeyPress]]
 +
* [[Virtual Key Codes]]

Revision as of 17:58, 11 July 2025

function isKeyPressed(Key) : Boolean

Returns true if the specified key is currently pressed.

Function Parameters

Parameter Type Description
Key Integer or Virtual Key Codes The virtual key code of the key to check (e.g., VK_F1, VK_SHIFT).

Returns

Boolean — true if the key is pressed, false otherwise.

Examples

if isKeyPressed(VK_SPACE) then
  print("Spacebar is currently pressed!")
end

if isKeyPressed(VK_LSHIFT) then
  print("Left Shift is pressed")
end

See also