Difference between revisions of "Lua:isKeyPressed"

From Cheat Engine
Jump to navigation Jump to search
m
m (Syntax Highlighting.)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' isKeyPressed(''Key'') ''':''' Boolean
+
{{CodeBox|'''function''' isKeyPressed(''Key'') ''':''' Boolean}}
  
 
Returns true if the specified key is currently pressed.
 
Returns true if the specified key is currently pressed.
Line 8: Line 8:
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
!style="width: 80%;background-color:white;" align="left"|Description
+
!style="width: 60%;background-color:white;" align="left"|Description
 
|-
 
|-
 
|Key
 
|Key
|Integer or [[Virtual Key Codes]]
+
|Integer or [[Virtual-Key Code]]
 
|The virtual key code of the key to check (e.g., <code>VK_F1</code>, <code>VK_SHIFT</code>).
 
|The virtual key code of the key to check (e.g., <code>VK_F1</code>, <code>VK_SHIFT</code>).
 
|}
 
|}
Line 19: Line 19:
  
 
===Examples===
 
===Examples===
<pre>
+
<syntaxhighlight lang="lua" line>
 
if isKeyPressed(VK_SPACE) then
 
if isKeyPressed(VK_SPACE) then
 
   print("Spacebar is currently pressed!")
 
   print("Spacebar is currently pressed!")
Line 27: Line 27:
 
   print("Left Shift is pressed")
 
   print("Left Shift is pressed")
 
end
 
end
</pre>
+
</syntaxhighlight>
  
== See also ==
+
{{LuaSeeAlso}}
* [[keyDown]]
+
 
* [[keyUp]]
+
{{KeyboardMouse}}
* [[doKeyPress]]
 
* [[Virtual Key Codes]]
 

Latest revision as of 20:16, 25 June 2026

<> Lua API Reference

function isKeyPressed(Key) : Boolean

Returns true if the specified key is currently pressed.

Function Parameters[edit]

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

Returns[edit]

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

Examples[edit]

1 if isKeyPressed(VK_SPACE) then
2   print("Spacebar is currently pressed!")
3 end
4 
5 if isKeyPressed(VK_LSHIFT) then
6   print("Left Shift is pressed")
7 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Mouse Related Functions

Keyboard Related Functions

Global Hotkey Related Functions