volvaga0 Posted November 28, 2012 Share Posted November 28, 2012 (edited) EDIT: SOLVED!!! Thank you steve40 for the sound advise. +Kudos to you my friend So I've been trying to get one of my mods to use a keypress function, but have not had any luck in getting it working. What I think will work, just doesn't and I just don't know why :wallbash: I've been trying to use the 'OnKeyUp' function to call some code, but have had no luck. Here is what I've got as of now: Function RegisterForKey(Int KeyCode) Native Function UnregisterForAllKeys() Native Import Input Import Form Event OnEquipped(Actor akActor) - INSERT CODE HERE - RegisterForKey(49) - INSERT CODE HERE - EndEvent Event OnKeyUp(int keyCode, float holdTime) if keyCode == 49 - INSERT CODE HERE - Debug.MessageBox("KeyPressed N") endif EndEvent Event OnUnEquipped(Actor akActor) UnregisterForAllKeys() EndEvent This script is being called from an item the player equipts, it should then register for the 'N' key, and call an action when that key is pressed. I'm not sure what I'm missing here as it's not working at all.Can the 'RegisterForKey()' not be called from within an event? Does it have to be from a function? I haven't found/seen much documentation on on SKSE keypress events so im not entirely sure what the correct syntax is, all this is from what I can gather from various Creation Kit wiki pages and a few mods that have working SKSE keypress events. If someone who knows what they are doing, could tell me what I'm doing wrong, please do! Edited November 29, 2012 by volvaga0 Link to comment Share on other sites More sharing options...
DreamKingMods Posted November 28, 2012 Share Posted November 28, 2012 To start with, you don't need--and shouldn't have--the first two lines, I don't think. Function RegisterForKey(Int KeyCode) NativeFunction UnregisterForAllKeys() Native You may well be overriding the SKSE functions with those local declarations. Link to comment Share on other sites More sharing options...
steve40 Posted November 28, 2012 Share Posted November 28, 2012 (edited) I agree with DreamKingMods. Those two functions are declared in the Form script, which you have imported into your script. Native functions should not be declared in your script. Edited November 28, 2012 by steve40 Link to comment Share on other sites More sharing options...
volvaga0 Posted November 28, 2012 Author Share Posted November 28, 2012 So I got rid of those top four lines, however I'm still getting no response from the key presses.The only reason I had those top two lines there was because the script wouldn't compile without them. It was something to do with my SKSE instal not being 'correct' somehow. I did a fresh copy/instal of the SKSE files and the script compiled correctly (without those line in them, as they wouldn't before). I thought that would solve my problems... NOPE. I don't understand why I can't get a response when using that code. I've even put the int value for the DXScancode in a global variable, and calling it using globalname.GetValueInt(), but that didn't get a response either (just trying different things to trigger a response). Is there a specific scriptreference where the Registerforkeypress() has to go? At the moment I have the code running in a 'Scriptname nameofscript extends ObjectReference'. Does it even matter? Link to comment Share on other sites More sharing options...
steve40 Posted November 29, 2012 Share Posted November 29, 2012 (edited) Did you check for runtime errors in your Papyrus log? RegisterForKey() belongs to Form script, so all you should need to do is: Form.RegisterForKey(codenumber) Edit: I was looking as Deathless Aphrodite's Sprint Jump and Boost mod to see how he uses SKSE to capture keypresses. He's running an OnUpdate loop every 0.1 seconds and continually checking Input.IsKeyPressed(code), he doesn't use RegisterForKey at all. You could try that method as a "plan B". Edited November 29, 2012 by steve40 Link to comment Share on other sites More sharing options...
volvaga0 Posted November 29, 2012 Author Share Posted November 29, 2012 Ill try the Form.RegisterForKey() when I get home. I dont want to have to resort do doing an onupdate() loop that often as that's quite intensive for what I want. Link to comment Share on other sites More sharing options...
volvaga0 Posted November 29, 2012 Author Share Posted November 29, 2012 Success! I have it working now :dance: The code as it was, is perfectly fine. It works with that code, minus the top 4 lines that is... I'm not entirely sure why this is, but the RegisterForKey() function (and the other SKSE functions) simply doesn't/wont work when written in an 'ObjectReference' script. I took your advise and had a quick look through my papyrus logs to see if it actually is being called, or is throwing out errors. Sure enough, it was giving an error: error: Unable to call RegisterForKey - no native object bound to the script object, or object is of incorrect type This lead me to believe the code wasn't being called, because it's not in the correct script extension. I made a quick blank Quest with a single script in it (the same code that is on the first post), called the sections of code via functions from my object reference script, and it worked! For a good lot of hours I've been wondering why my sections of, seemingly correct code; wasn't working. It was in fact correct, but being called from the wrong script extension, causing the errors. Thanks for the assistance and the will to help a fellow modder through his troubles, it's an honor to be a part of this solid community. Thanks again! Link to comment Share on other sites More sharing options...
steve40 Posted November 30, 2012 Share Posted November 30, 2012 That's good to hear. It's a bit odd though, as ObjectReference script extends Form script, so in theory, RegisterForKey() should work in an ObjectReference script. Link to comment Share on other sites More sharing options...
Recommended Posts