- Found in:
- SKSE
Description
Wiki Description
Checks if a given key is currently pressed. (This function requires SKSE)
Documentation Comment
returns whether a key is pressed
Caveats
CK Wiki - Notes
- To avoid multithreading mishaps, it's generally best to use Form.RegisterForSingleUpdate(...) rather than Form.RegisterForUpdate(...).
- If updating at tight intervals, optimization is key as it will make your polling script more responsive. It shouldn't be necessary to update at intervals < 0.25 and doing so just makes a script unnecessarily 'expensive'.
- Given the Form are available, they'll be preferable to the above polling methods for many applications as their 'cost' is less.
- Avoid using keys already claimed by Skyrim. Invariably, mod added hotkeys will conflict, so it's best to offer a way to rebind your hotkey(s) via Input.GetNthKeyPressed(...) from an Options Menu or other readily accessible means such as a scripted inventory item. This will afford your mod elasticity and allow it to work in tandem with other hotkey bearing mods.
- Using a property to store the dxKeycode of the key you are polling will allow the same script to be easily reused to poll for different keys simultaneously, as this allows the dxKeycode to be set (or the default value overridden) in the Creation Kit without editing the script's source
Parameters
Examples
Bool bIsHotkeyPressed = Input.IsKeyPressed(42) ; Is L-Shift pressed?Bool bIsHotkeyPressed ; = False
Int Property iHotkey = 184 Auto ; R-Alt by default
Event OnInit()
RegisterForSingleUpdate(0.25)
EndEvent
Event OnUpdate()
If bIsHotkeyPressed != Input.IsKeyPressed(iHotkey) ; Only run code when the status changes
bIsHotkeyPressed = !bIsHotkeyPressed ; Set bool to whatever it isn't
If bIsHotkeyPressed ; == True
Debug.Trace("Hotkey Pressed")
Else ; If bIsHotkeyPressed == False
Debug.Trace("Hotkey Released")
EndIf
EndIf
RegisterForSingleUpdate(0.25)
EndEventEvent OnUpdate()
If bIsHotkeyPressed != Input.IsKeyPressed(iHotkey)
bIsHotkeyPressed = !bIsHotkeyPressed
If bIsHotkeyPressed
Debug.Trace("Do something.")
EndIf
EndIf
RegisterForSingleUpdate(0.25)
EndEventAuto-Generated Example
int myInt__dxKeycode
bool returnedValue = Input.IsKeyPressed(myInt__dxKeycode)