Jump to content

[LE] where i must input this => IsKeyPressed


Recommended Posts

sorry for my bad english,

i like to test this script :

// begin

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)
EndEvent

// end

 

note : i got this from https://www.creationkit.com/index.php?title=IsKeyPressed_-_Input

 

but it require SKSE, so, where i must put it in, its require creation kit? what tab i must put in?

 

i mean it do not have object reference to trigger the events, so i dont understand how to put this script without object to put the script

Edited by virginharvester
Link to comment
Share on other sites

Genrally you'd put this stuff in a script in a quest with the start game enabled checkbox checked. Also it's better to use https://www.creationkit.com/index.php?title=RegisterForKey_-_Form + https://www.creationkit.com/index.php?title=OnKeyDown_-_Form instead of checking constantly if the key is pressed.

And yeah you of course need ck to bind scripts to objects.

Edited by FrankFamily
Link to comment
Share on other sites

Yes you need a new quest to add the script to, doesn't need a name, category or anything just start game enabled flag and ID ofc.

About skse, afaik you will need to download if you haven't already the script sources for skse in order to compile the script so the CK knows those skse functions you are calling exist and that's it.

Edited by FrankFamily
Link to comment
Share on other sites

thanks again for reply, i have test it but encounter some problem

 

this is script :

 

Scriptname HotkeyScript

Function RegisterForKey(Int KeyCode) Native

Event OnKeyDown(Int KeyCode)
Debug.Trace("A registered key has been pressed")
If KeyCode == 42
Debug.Trace("R-Shift is registered and has been pressed")
EndIf
EndEvent

(the script compile succeed without error)

this is quest data tab

ID : HotkeyScript

quest name : Hotkey Quest

priority : 100

type : non

start game enable check, run once check,

 

save it, run the game, when i press r-shift, the script not respond,

any wrong with my doing?

note : i have latest SKSE instaled (oldrim)

Link to comment
Share on other sites

Well, you are not calling registerforkey, there you are defining a function instead. You need to call it just like registerforsingleupdate within onupdate in your original script, passing 42 as the parameter keycode, i.e:

 

Event Oninit()

RegisterForKey(42)

EndEvent

 

In the wiki check the examples not just the syntax section

Edited by FrankFamily
Link to comment
Share on other sites

thanks again for reply,

but still not work,

i have modified with other script,

but still not work.

 

Scriptname HotkeyScript

Function Init()
RegisterForKey(42)
Debug.MessageBox("The mod has been installed")
EndFunction

Event OnPlayerLoadGame()
Debug.Trace("player loaded a save, do some fancy stuff")
endEvent

Function RegisterForKey(Int KeyCode) Native

Event OnKeyDown(Int KeyCode)
Debug.Trace("A registered key has been pressed")
If KeyCode == 42
Debug.Trace("R-Shift is registered and has been pressed")
Debug.Trace("The keycode '"+keyCode+"' has been pressed.")
EndIf
EndEvent

Link to comment
Share on other sites

Try building off of the following. A most basic variation of what you're trying to do.

 

 

Scriptname HotkeyScript Extends Quest

Event OnInit()
  RegiserForKey(42)
EndEvent

Event OnKeyDown(Int KeyCode)
  If KeyCode == 42
    Debug.Notification("Hey, you pressed the key with a DXScanCode value of "+KeyCode)
  EndIf
EndEvent

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...