Difference between revisions of "OnKeyDown - ScriptObject"

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search
imported>Qazaaq
(Replaced input script with DX Scan Code)
imported>Qazaaq
(added required f4se version)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Scripting]]
[[Category:Papyrus]]
[[Category:F4SE]]
'''F4SE Member of:''' [[ScriptObject Script]]
'''F4SE Member of:''' [[ScriptObject Script]]
 
{{Template:Papyrus:RequiredF4SE|version=0.3.0}}
Minimum required F4SE Version: 0.3.0


Listens for the pressing of keys whose [[DirectX Scan Codes|Scan Codes]] have been registered via [[RegisterForKey - ScriptObject|RegisterForKey]].
Listens for the pressing of keys whose [[DirectX Scan Codes|Scan Codes]] have been registered via [[RegisterForKey - ScriptObject|RegisterForKey]].
Line 12: Line 8:


== Parameters ==
== Parameters ==
*KeyCode: The [[DirectX Scan Codes|Scan Code]] of a key press to listen for.
*keyCode: The [[DirectX Scan Codes|Scan Code]] of a key press to listen for.


== Examples ==
== Examples ==
<source lang="papyrus">
<source lang="papyrus">
Event OnKeyDown(int keyCode)
Event OnKeyDown(int keyCode)
  Debug.Trace("A registered key has been pressed")
   If (keyCode == 160)
   If (keyCode == 160)
       Debug.Trace("L-Shift is registered and has been pressed")
       Debug.Trace("The left shift key has been pressed.")
  ElseIf (keyCode == 161)
      Debug.Trace("The right shift key has been pressed.")
  Else
      Debug.Trace("The keycode '"+keyCode+"' has been pressed.")
   EndIf
   EndIf
EndEvent
EndEvent
Line 33: Line 32:
*[[OnKeyUp - ScriptObject]]
*[[OnKeyUp - ScriptObject]]
*[[DirectX Scan Codes]]
*[[DirectX Scan Codes]]
[[Category:Scripting]]
[[Category:Papyrus]]
[[Category: Events]]
[[Category:F4SE]]

Latest revision as of 18:39, 21 January 2018

F4SE Member of: ScriptObject Script
Requires F4SE version 0.3.0 or higher.

Listens for the pressing of keys whose Scan Codes have been registered via RegisterForKey.

Syntax[edit | edit source]

Event OnKeyDown(int keyCode)

Parameters[edit | edit source]

  • keyCode: The Scan Code of a key press to listen for.

Examples[edit | edit source]

Event OnKeyDown(int keyCode)
   If (keyCode == 160)
      Debug.Trace("The left shift key has been pressed.")
   ElseIf (keyCode == 161)
      Debug.Trace("The right shift key has been pressed.")
   Else
      Debug.Trace("The keycode '"+keyCode+"' has been pressed.")
   EndIf
EndEvent

Notes[edit | edit source]

  • If multiple keys are registered, you'll want to differentiate in the event body as demonstrated above. If only one key will be registered for the form, such differentiation is not necessary.

See Also[edit | edit source]