Difference between revisions of "Lua:doKeyPress"

From Cheat Engine
Jump to navigation Jump to search
m
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' doKeyPress(''key'')
+
'''function''' doKeyPress(''Key'')
  
Simulates a keypress (up/down)
+
Simulates a key press by sending a key down followed by a key up event for the specified key.
 
 
Tip: To differentiate between highercase and lowercase set the shift key down or up depending on what you wish
 
  
 
===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 Code]]
|The keycode for the key to emulated
+
|The virtual key code of the key to press (e.g., <code>VK_F1</code>, <code>VK_SHIFT</code>).
 
|}
 
|}
  
 +
===Examples===
 +
<pre>
 +
-- Simulate pressing the Enter key
 +
doKeyPress(VK_RETURN)
 +
 +
-- Simulate pressing the "A" key
 +
doKeyPress(VK_A)
 +
</pre>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
 +
* [[Virtual-Key Code]]
  
 
=== Related Functions ===
 
=== Related Functions ===
* [[keyUp]]
+
* [[Lua:keyUp|keyUp]]
* [[keyDown]]
+
* [[Lua:keyDown|keyDown]]
* [[Virtual-Key Code]]
 

Latest revision as of 18:02, 11 July 2025

function doKeyPress(Key)

Simulates a key press by sending a key down followed by a key up event for the specified key.

Function Parameters[edit]

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

Examples[edit]

-- Simulate pressing the Enter key
doKeyPress(VK_RETURN)

-- Simulate pressing the "A" key
doKeyPress(VK_A)

See also[edit]

Related Functions[edit]