arpharazonn Posted October 30, 2019 Share Posted October 30, 2019 Hey guys, i need help. How i can simulate a key press (for toggle enb) when i read "any" book. I tried something with scripts, when i use a quest and a specific book its okay. But i need it to work for any books not a specific one. Am i need esp or quest or anything for this besides script file? Thanks! Link to comment Share on other sites More sharing options...
ReDragon2013 Posted October 30, 2019 Share Posted October 30, 2019 (edited) maybe this is working for you.. not tested just an approach arphaPlayerAliasScript Scriptname arphaPlayerAliasScript extends ReferenceAlias ; https://forums.nexusmods.com/index.php?/topic/8106698-how-to-simulate-key-press-when-read-any-book/ ; use the quest you have, make a new Alias fill with Player and attach this script ; make the quest start on game enabled ; -- EVENTs -- EVENT OnInit() ENDEVENT EVENT OnPlayerLoadGame() ENDEVENT EVENT OnRead() ; received when this object (a book) is read IF (SKSE.GetVersion() > 0) ; https://www.creationkit.com/index.php?title=SKSE_Script ; https://www.creationkit.com/index.php?title=TapKey_-_Input ; https://www.creationkit.com/index.php?title=Input_Script#DXScanCodes ; your code to simulate a key press, but that need SKSE Input.TapKey(15) ; 0x0000000F TAB for example ;;; actor player = self.GetActorReference() WHILE (TRUE) IF Utility.IsInMenuMode() Utility.Wait(0.5) ; just wait for closing the book ELSE Input.TapKey(16) ; 0x00000010 simulate another key for ENB, ONLY if required RETURN ; - STOP - leave the loop and close the event ENDIF ENDWHILE ENDIFENDEVENT EDIT: Sorry script above is not working, because playerAlias is not a bookAlias as you already know. The event OnRead() is only working for books within a ReferenceAlias or ObjectReference script,where SELF (the script attached object or alias) is a book! For bookshelves exist three scripts: PlayerBookShelfTriggerSCRIPT.psc PlayerBookShelfClickTriggerSCRIPT.psc PlayerBookShelfContainerScript.pscNote: For every "PlayerBookShelfContainerScript" should exist a related "PlayerBookShelfTriggerScript". The PlayerBookShelfClickTriggerSCRIPT" is different, which depends on the amount of filled bookshelves. You could experiment with events in the triggerscripts to launch the keypress code. Edited October 31, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 30, 2019 Share Posted October 30, 2019 I would suggest using SKSE added papyrus code. You can register for the "Book Menu" and set it up so that whenever it opens and closes you can toggle off and on your ENB. OnMenuOpenOnMenuCloseRegisterForMenu Furthermore, you can use SKSE added papyrus code to "tap" any key that you need. TapKey Link to comment Share on other sites More sharing options...
arpharazonn Posted October 30, 2019 Author Share Posted October 30, 2019 maybe this is working for you.. not tested just an approach arphaPlayerAliasScript Scriptname arphaPlayerAliasScript extends ReferenceAlias ; https://forums.nexusmods.com/index.php?/topic/8106698-how-to-simulate-key-press-when-read-any-book/ ; use the quest you have, make a new Alias fill with Player and attach this script ; make the quest start on game enabled ; -- EVENTs -- EVENT OnInit() ENDEVENT EVENT OnPlayerLoadGame() ENDEVENT EVENT OnRead() ; received when this object (a book) is read IF (SKSE.GetVersion() > 0) ; https://www.creationkit.com/index.php?title=SKSE_Script ; https://www.creationkit.com/index.php?title=TapKey_-_Input ; https://www.creationkit.com/index.php?title=Input_Script#DXScanCodes ; your code to simulate a key press, but that need SKSE Input.TapKey(15) ; 0x0000000F TAB for example actor player = self.GetActorReference() WHILE (TRUE) IF Utility.IsInMenuMode() Utility.Wait(0.5) ; just wait for closing the book ELSE Input.TapKey(16) ; 0x00000010 simulate another key for ENB, ONLY if required RETURN ; - STOP - leave the loop and close event ENDIF ENDWHILE ENDIFENDEVENT EDIT: Sorry script above is not working, because playerAlias is not a bookAlias as you already know. The event OnRead() is only working for books within a ReferenceAlias or ObjectReference script,where SELF (the script attached object or alias) is a book! For bookshelves exist three scripts: PlayerBookShelfTriggerSCRIPT.psc PlayerBookShelfClickTriggerSCRIPT.psc PlayerBookShelfContainerScript.pscNote: For every "PlayerBookShelfContainerScript" should exist a related "PlayerBookShelfTriggerScript". The PlayerBookShelfClickTriggerSCRIPT" is different, which depends on the amount of filled bookshelves. You could experiment with events in the triggerscripts to launch the keypress code. I would suggest using SKSE added papyrus code. You can register for the "Book Menu" and set it up so that whenever it opens and closes you can toggle off and on your ENB. OnMenuOpenOnMenuCloseRegisterForMenu Furthermore, you can use SKSE added papyrus code to "tap" any key that you need. TapKey Thanks both of you!! I got the main idea (i think) and i make this: Scriptname enbbookfixs extends Quest Event OnInit() RegisterForMenu("BookMenu") EndEvent Event OnMenuOpen(String MenuName) Debug.Trace("A registered menu has opened.") If MenuName == "BookMenu" Debug.Trace("BookMenu has been registered and has opened.") ; TEST EndIf EndEvent Event OnMenuClose(String MenuName) Debug.Trace("A registered menu has closed.") If MenuName == "BookMenu" Debug.Trace("BookMenu has been registered and has closed.") ; TEST EndIf EndEvent So for activate the script i have to create a quest and attach the script. Is it true or am i still missing something? Btw, i could not attach script to the quest, creation kit dont see the script and when i try making new script, giving fatal error. EDIT: So i create a quest, and attached script above. No error on Papyrus0 log but no success also :) Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 31, 2019 Share Posted October 31, 2019 I suspect that the quest is not running which may be why you have not gotten any trace statements in your papyrus log. For your purpose, I think you would want to use a quest that has the "start game enabled" box checked. This would cause the quest to start immediately upon next game load after the plugin has been activated. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted October 31, 2019 Share Posted October 31, 2019 (edited) https://www.creationkit.com/index.php?title=UI_Script#Valid_Menu_Namesyour code is If MenuName == "BookMenu"it should be If (MenuName == "Book Menu")Some menu names have a space inside. Edited October 31, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
arpharazonn Posted October 31, 2019 Author Share Posted October 31, 2019 (edited) I suspect that the quest is not running which may be why you have not gotten any trace statements in your papyrus log. For your purpose, I think you would want to use a quest that has the "start game enabled" box checked. This would cause the quest to start immediately upon next game load after the plugin has been activated. Thank you. Its checked already. Also i tried start it with console commands but still nothing appear on logs. https://www.creationkit.com/index.php?title=UI_Script#Valid_Menu_Names your code is If MenuName == "BookMenu"it should be If (MenuName == "Book Menu")Some menu names have a space inside. Thank you. I fixed it. But still no log appear. :sad: I don't know where i'm wrong. EDIT: Now it works!! I followed this guide for creating quest: https://forums.nexusmods.com/index.php?/topic/558795-script-tutorial-script-initialization-on-game-load/ And script work fine. But this Input.TapKey(145) seems not work. :sad: Here is the last form of script Scriptname enbfixbookscript extends Quest Function Init() Debug.MessageBox("The mod has been installed") EndFunction Event OnInit() RegisterForMenu("Book Menu") EndEvent Event OnMenuOpen(String MenuName) Debug.Trace("A registered menu has opened.") If MenuName == "Book Menu" Input.TapKey(70) ; scroll lock?? EndIf EndEvent Event OnMenuClose(String MenuName) Debug.Trace("A registered menu has closed.") If MenuName == "Book Menu" Input.TapKey(145) ; scroll lock?? EndIf EndEvent Edited October 31, 2019 by arpharazonn Link to comment Share on other sites More sharing options...
ReDragon2013 Posted October 31, 2019 Share Posted October 31, 2019 (edited) You wrote: "But this Input.TapKey(145) seems not work."As you can see this DXScancode was not listen here. https://www.creationkit.com/index.php?title=Input_Script#DXScanCodes maybe next script has new info to solve your problem:arphaQuestScriptENBBookfix Scriptname arphaQuestScriptENBBookfix extends Quest ; https://forums.nexusmods.com/index.php?/topic/8106698-how-to-simulate-key-press-when-read-any-book/ String sName = "Book Menu" Int iKey = 70 ; -- EVENTs -- EVENT OnInit() IF (SKSE.GetVersion() > 0) Debug.MessageBox("OnInit() - enbbookfix mod has been installed! " +self) self.RegisterForMenu(sName) self.RegisterForKey(iCode) ; Is this key working? for debugging only ENDIF ENDEVENT ; *** KEY *** https://www.creationkit.com/index.php?title=RegisterForKey_-_Form EVENT OnKeyDown(Int KeyCode) IF (KeyCode == iKey) Debug.Trace("DXScanCode " +KeyCode+ " is down..") ENDIF ENDEVENT EVENT OnKeyUp(Int KeyCode) IF (KeyCode == iKey) Debug.Trace("DXScanCode " +KeyCode+ " is up..") ENDIF ENDEVENT ; *** MENU *** https://www.creationkit.com/index.php?title=RegisterForMenu_-_Form EVENT OnMenuOpen(String MenuName) ; required SKSE v1.06.00 IF (MenuName == sName) ; "If multiple menus are registered, you'll want to differentiate in the corresponding event body. ; If only one menu is to be registered, no such differentiation is necessary." myF_Action(1) ENDIF ENDEVENT EVENT OnMenuClose(String MenuName) IF (MenuName == sName) myF_Action(0) ENDEVENT ; -- FUNCTION -- ; https://www.creationkit.com/index.php?title=Input_Script#DXScanCodes ; https://www.creationkit.com/index.php?title=TapKey_-_Input ; https://www.creationkit.com/index.php?title=HoldKey_-_Input ;------------------------- FUNCTION myF_Action(Int i) ; TapKey() required SKSE v1.05.04 ;------------------------- IF (i == 1) Debug.Trace("A registered Bookmenu has opened.") ; debugging only Input.TapKey(iKey) ; scroll lock?? ;;; ELSEIF (i == 0) ELSE Debug.Trace("A registered Bookmenu has closed!") ; debugging only Input.TapKey(145) ; 145 does not exist as ScanKey! ENDIF ENDFUNCTION ;---------------------------- FUNCTION myF_ActionHRK(Int i) ; HoldKey(), ReleaseKey() required SKSE v1.05.04 ;---------------------------- IF (i == 1) Debug.Trace("A registered Bookmenu has opened.") ; debugging only Input.HoldKey(iKey) ;;; ELSEIF (i == 0) ELSE Debug.Trace("A registered Bookmenu has closed!") ; debugging only Input.ReleaseKey(iKey) ; Releases a key held by HoldKey. ENDIF ENDFUNCTION ;------------------------ FUNCTION myF_UnRegister() ;------------------------ self.UnregisterForAllKeys() self.UnregisterForAllMenus() ENDFUNCTION Edited October 31, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
arpharazonn Posted October 31, 2019 Author Share Posted October 31, 2019 (edited) You wrote: "But this Input.TapKey(145) seems not work."As you can see this DXScancode was not listen here. https://www.creationkit.com/index.php?title=Input_Script#DXScanCodes maybe next script has new info to solve your problem:arphaQuestScriptENBBookfix Scriptname arphaQuestScriptENBBookfix extends Quest ; https://forums.nexusmods.com/index.php?/topic/8106698-how-to-simulate-key-press-when-read-any-book/ String sName = "Book Menu" Int iKey = 70 ; -- EVENTs -- EVENT OnInit() IF (SKSE.GetVersion() > 0) Debug.MessageBox("OnInit() - enbbookfix mod has been installed! " +self) self.RegisterForMenu(sName) self.RegisterForKey(iCode) ; Is this key working? for debugging only ENDIF ENDEVENT ; *** KEY *** https://www.creationkit.com/index.php?title=RegisterForKey_-_Form EVENT OnKeyDown(Int KeyCode) IF (KeyCode == iKey) Debug.Trace("DXScanCode " +KeyCode+ " is down..") ENDIF ENDEVENT EVENT OnKeyUp(Int KeyCode) IF (KeyCode == iKey) Debug.Trace("DXScanCode " +KeyCode+ " is up..") ENDIF ENDEVENT ; *** MENU *** https://www.creationkit.com/index.php?title=RegisterForMenu_-_Form EVENT OnMenuOpen(String MenuName) ; required SKSE v1.06.00 IF (MenuName == sName) ; "If multiple menus are registered, you'll want to differentiate in the corresponding event body. ; If only one menu is to be registered, no such differentiation is necessary." myF_Action(1) ENDIF ENDEVENT EVENT OnMenuClose(String MenuName) IF (MenuName == sName) myF_Action(0) ENDEVENT ; -- FUNCTION -- ; https://www.creationkit.com/index.php?title=Input_Script#DXScanCodes ; https://www.creationkit.com/index.php?title=TapKey_-_Input ; https://www.creationkit.com/index.php?title=HoldKey_-_Input ;------------------------- FUNCTION myF_Action(Int i) ; TapKey() required SKSE v1.05.04 ;------------------------- IF (i == 1) Debug.Trace("A registered Bookmenu has opened.") ; debugging only Input.TapKey(iKey) ; scroll lock?? ;;; ELSEIF (i == 0) ELSE Debug.Trace("A registered Bookmenu has closed!") ; debugging only Input.TapKey(145) ; 145 does not exist as ScanKey! ENDIF ENDFUNCTION ;---------------------------- FUNCTION myF_ActionHRK(Int i) ; HoldKey(), ReleaseKey() required SKSE v1.05.04 ;---------------------------- IF (i == 1) Debug.Trace("A registered Bookmenu has opened.") ; debugging only Input.HoldKey(iKey) ;;; ELSEIF (i == 0) ELSE Debug.Trace("A registered Bookmenu has closed!") ; debugging only Input.ReleaseKey(iKey) ; Releases a key held by HoldKey. ENDIF ENDFUNCTION ;------------------------ FUNCTION myF_UnRegister() ;------------------------ self.UnregisterForAllKeys() self.UnregisterForAllMenus() ENDFUNCTION Thank you so much!! Im grateful! After little adjustments it worked. Actually log says that. But it doesnt toggle enb... When i press manually Q from keyboard log says "key 16 is down". So script working as intended and presses the key when book opens... Maybe problem is: simulated key press with script dont affect ENB? Log (i removed key up log tracing) [10/31/2019 - 09:19:40PM] A registered Bookmenu has opened.[10/31/2019 - 09:19:40PM] DXScanCode 16 is down..[10/31/2019 - 09:19:42PM] A registered Bookmenu has closed![10/31/2019 - 09:19:42PM] DXScanCode 16 is down..[10/31/2019 - 09:19:43PM] A registered Bookmenu has opened.[10/31/2019 - 09:19:43PM] DXScanCode 16 is down..[10/31/2019 - 09:19:44PM] A registered Bookmenu has closed![10/31/2019 - 09:19:44PM] DXScanCode 16 is down.. Edit: The problem is not enb. I changed code to 88 which is F12 and my steam screenshot shortcut. Log says key is down but there is no screenshot. Maybe in game simulated key presses dont affect windows or something unrelated with game engine? Like steam screenshot, like enb etc... I lost Edited October 31, 2019 by arpharazonn Link to comment Share on other sites More sharing options...
ReDragon2013 Posted October 31, 2019 Share Posted October 31, 2019 (edited) I am a bit confused. your wrote (first posting): "I tried something with scripts, when i use a quest and a specific book its okay." and now in last posting: "Maybe problem is: simulated key press with script dont affect ENB?"Question: What have you done to get the single book (ENB switch) working? ---similar other way: use SKSE plugins to save DXScanCode into textfile on your PC jContainers: https://www.nexusmods.com/skyrim/mods/49743 papyrusUtils: https://www.nexusmods.com/skyrim/mods/58705/ JsonUtil.psc MiscUtil.psc -> ; Write string to file. bool function WriteToFile(string fileName, string text, bool append = true, bool timestamp = false) global nativeuse a batch file started in background before Skyrim (like "wait4keypress.bat", good old dos file) - to look for changing filesize IF yes - get the stored key from textfile and simulate keypress of this key - and remove the textfile ENDIF - go back to filesize comparing but this is far from Skyrim modding, you will need some PC programming skills https://en.wikibooks.org/wiki/Windows_Batch_Scripting Edited October 31, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
Recommended Posts