1,482
edits
imported>Egocarib m (→See Also) |
m (Convert source tags to syntaxhighlight) |
||
| Line 9: | Line 9: | ||
== Syntax == | == Syntax == | ||
< | <syntaxhighlight lang="papyrus">Bool Function IsKeyPressed(Int dxKeycode) Global Native</syntaxhighlight> | ||
== Parameters == | == Parameters == | ||
| Line 19: | Line 19: | ||
== Examples == | == Examples == | ||
*Standard use. | *Standard use. | ||
< | <syntaxhighlight lang="papyrus">Bool bIsHotkeyPressed = Input.IsKeyPressed(42) ; Is L-Shift pressed?</syntaxhighlight> | ||
*Do/Undo something when a key is pressed/released. [[States (Papyrus)|States]] ''could'' be used in lieu of the boolean guard, but would verifiably not save any resources in this context. | *Do/Undo something when a key is pressed/released. [[States (Papyrus)|States]] ''could'' be used in lieu of the boolean guard, but would verifiably not save any resources in this context. | ||
< | <syntaxhighlight lang="papyrus">Bool bIsHotkeyPressed ; = False | ||
Int Property iHotkey = 184 Auto ; R-Alt by default | Int Property iHotkey = 184 Auto ; R-Alt by default | ||
| Line 38: | Line 38: | ||
EndIf | EndIf | ||
RegisterForSingleUpdate(0.25) | RegisterForSingleUpdate(0.25) | ||
EndEvent</ | EndEvent</syntaxhighlight> | ||
*Do something exactly once each time a key is pressed. We'll take the scaffolding from above as rendered given the difference is exclusively in the OnUpdate event. Without the primary check and consecutive bool-flip, [[Trace - Debug|Trace]] would be called every iteration. | *Do something exactly once each time a key is pressed. We'll take the scaffolding from above as rendered given the difference is exclusively in the OnUpdate event. Without the primary check and consecutive bool-flip, [[Trace - Debug|Trace]] would be called every iteration. | ||
< | <syntaxhighlight lang="papyrus">Event OnUpdate() | ||
If bIsHotkeyPressed != Input.IsKeyPressed(iHotkey) | If bIsHotkeyPressed != Input.IsKeyPressed(iHotkey) | ||
bIsHotkeyPressed = !bIsHotkeyPressed | bIsHotkeyPressed = !bIsHotkeyPressed | ||
| Line 48: | Line 48: | ||
EndIf | EndIf | ||
RegisterForSingleUpdate(0.25) | RegisterForSingleUpdate(0.25) | ||
EndEvent</ | EndEvent</syntaxhighlight> | ||
== Notes == | == Notes == | ||