Difference between revisions of "Lua:isKeyPressed"
Jump to navigation
Jump to search
(Created page with ''''function''' isKeyPressed(''key'') Returns true if the given keycode is valid and pressed down ===Function Parameters=== {|width="85%" cellpadding="10%" cellpadding="5%" cell…') |
m (Syntax Highlighting.) |
||
| (9 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | '''function''' isKeyPressed('' | + | [[Category:Lua]] |
| + | {{CodeBox|'''function''' isKeyPressed(''Key'') ''':''' Boolean}} | ||
| − | Returns true if the | + | Returns true if the specified key is currently pressed. |
===Function Parameters=== | ===Function Parameters=== | ||
| − | {|width="85%" cellpadding="10 | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
!align="left"|Parameter | !align="left"|Parameter | ||
!align="left"|Type | !align="left"|Type | ||
| − | !style="width: | + | !style="width: 60%;background-color:white;" align="left"|Description |
|- | |- | ||
| − | | | + | |Key |
| − | |[[Virtual-Key Code]] | + | |Integer or [[Virtual-Key Code]] |
| − | |The | + | |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. | ||
| − | == | + | ===Examples=== |
| − | + | <syntaxhighlight lang="lua" line> | |
| − | + | if isKeyPressed(VK_SPACE) then | |
| + | print("Spacebar is currently pressed!") | ||
| + | end | ||
| + | |||
| + | if isKeyPressed(VK_LSHIFT) then | ||
| + | print("Left Shift is pressed") | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | {{LuaSeeAlso}} | ||
| + | |||
| + | {{KeyboardMouse}} | ||
Latest revision as of 20:16, 25 June 2026
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