ModdedMeghan Posted December 2, 2022 Share Posted December 2, 2022 I mean the title pretty much says it all, I'm just trying to get my script to find the actual keycode when the player rebinds the hotkey via the MCM.I currently have my script able to detect the fact that the hotkey has been rebound, but I cannot for the life of me figure out how to get it to extract the keycode and I can't seem to find any examples of this being done either. Which feels weird to me cause I can't be the only person whose ever wanted to do this right? I'm probably overlooking something really simple as usual but for now I'm at a total loss. Any help would be highly appreciated. Link to comment Share on other sites More sharing options...
RaidersClamoring Posted December 2, 2022 Share Posted December 2, 2022 Did you download and look at the source scripts in "Optional files: MCM Demo"?I suppose you did since you're able to detect the event. Using their example It should be (OnInit or something) RegisterForExternalEvent("OnMCMSettingChange|YourMod", "OnMCMSettingChange" (Then unleashed by your mod somewhere:)Function OnMCMSettingChange(string modName, string id) Int KeySetting = GetModSettingInt(ModName, id)EndFunction Or if you are using CustomEvent RegisterForCustomEvent(YourScriptAsVariable, "OnMyCustomEvent") Event ActualScriptName.OnMyCustomEvent(ActualScriptName JustSomethingHere, Var[] kArgs)Int KeySetting = kArgs[1] as intEndEvent Link to comment Share on other sites More sharing options...
ModdedMeghan Posted December 3, 2022 Author Share Posted December 3, 2022 (edited) Hmm I tried this, and a few other things but it keeps returning "-1"I also tried making a settings.ini to hold the int but the MCM always sets it to "0" no matter what key I pick. I think it's cause the way MCM deals with hotkeys they're not technically an int in and of themselves. But I know the MCM itself can somehow retrieve an int for it because:1: All the keycodes are ints2: If I go to "Data\MCM\Settings\Keybinds.json" I can see this "{"keybinds":[{"id":"ListeningModeKey","keycode":101,"modName":"HearingDamage","modifiers":0}],"version":1}" Edited December 3, 2022 by ModdedMeghan Link to comment Share on other sites More sharing options...
RaidersClamoring Posted December 3, 2022 Share Posted December 3, 2022 I assumed they are int-s only due to the decimal scan codes used. But maybe they return a character as a string? This worked for me as a means of testing -- for a while, then it started crashing. Do you get crashes? Event OnInit() RegisterForExternalEvent("OnMCMSettingChange", "OnMCMSettingChange") Debug.Trace("MCM is installed: " + IsInstalled())EndEventFunction OnMCMSettingChange(String Modname, String ID) Debug.Trace("Modname: " + ModName + ", ID: " + ID) Debug.Trace("\nValues:\n-------------") Debug.Trace("Bool? " + GetModSettingBool(ModName, ID)) Debug.Trace("Int? " + GetModSettingInt(ModName, ID)) Debug.Trace("Float? " + GetModSettingFloat(ModName, ID)) Debug.Trace("String? " + GetModSettingString(ModName, ID))EndFunction It put out this:[12/03/2022 - 10:24:09AM] MCM is installed: True[12/03/2022 - 10:24:32AM] Modname: MCM, ID: iPosition:Main[12/03/2022 - 10:24:32AM] Values:-------------[12/03/2022 - 10:24:32AM] Bool? True[12/03/2022 - 10:24:32AM] Int? 2[12/03/2022 - 10:24:32AM] Float? 0.000000 Link to comment Share on other sites More sharing options...
ModdedMeghan Posted December 4, 2022 Author Share Posted December 4, 2022 (edited) So when I ran those traces I got somewhat different results:[12/03/2022 - 08:56:03PM] Modname: HearingDamage, ID: iListeningModeKey:Main[12/03/2022 - 08:56:03PM] Values:-------------[12/03/2022 - 08:56:03PM] Bool? False[12/03/2022 - 08:56:03PM] Int? 0[12/03/2022 - 08:56:03PM] Float? 0.000000 And then it crashes when it tries to print the string But then I tried changing the trace on the string to a message box, and when I do that the game doesn't crash. However the message box just returns an empty string, or maybe even no string at all? No string could explain the crashing. What's kinda weird is I actually had been checking for string at some point earlier in this process and at that time it would return a string identical to the int (either -1 or 0) so I'm not sure why it's totally empty this time around. Edited December 4, 2022 by ModdedMeghan Link to comment Share on other sites More sharing options...
RaidersClamoring Posted December 4, 2022 Share Posted December 4, 2022 The string-check is where I crash too. Funnily enough printing it to the console works, Trace() is what's pooping itself.Anyway, it appears your setting is a "modifier", the value is an int and it genuinely is 0 i.e. unset. Something is malformed elsewhere in the code? Link to comment Share on other sites More sharing options...
ModdedMeghan Posted December 5, 2022 Author Share Posted December 5, 2022 I don't think the problem is in my code tbh (For once lol) I think it's just the way the MCM handles hotkeys. Although the keycode is an int, the hotkey itself isn't actually an int (although it does have access to the keycode)...and I can't seem to get access to that keycode myself. Doesn't mean what I'm trying to do is impossible...although I suspect it might be honestly It's not the end of the world. I have an idea for another way to achieve the same end goal...it's just not as elegant, and easier to screw up That said thank you so much for your help and time! Link to comment Share on other sites More sharing options...
CrEaToXx Posted December 5, 2022 Share Posted December 5, 2022 Nothing in the FO4 Payrus is "technically" an int. Consult the CK Wiki in that regard. But that may not even be your problem. The MCM handles keybinds internally via the .dll and flash file, so the "standard" F4SE code to catch the hotkey might not work. I tried as well and it didn't. So I had to find ways around it. I guess the necessity never arose because with the release of registrators hotkey mod all problems were solved. Unfortunately that also means a huge chunk of functions present in SSE, are not present F4SE. Let us know if you manage to come up with something. You can verify that by trying to rebind some unicode keys in MCM. While these are perfectly working in the vanilla keybind menu, they do not work in the MCM. On my German keyboard this is true for the <>, the print and the pause key. There might be others. MCM also can't catch the difference between left/right shift and ctrl. Link to comment Share on other sites More sharing options...
ModdedMeghan Posted December 6, 2022 Author Share Posted December 6, 2022 I'm curious about nothing technically being an int. I tried to find something on the wiki, but couldn't find anything about it. Which is a shame sounds interesting, would love to read up on it. Anyway I did find a way around the issue...sorta.Basically I released a mod about a year ago and as an award for completing the main quest it's possible to unlock a new ability which is activated by holding the "B" key. Of course it can also be rebound using the holotape settings menu I included at the time.Then I decided recently to add an MCM. But I also don't want to force people to use the MCM if they don't feel like it so I needed the to keep the holotape option fully functional. Anyway my original plan was to have the MCM hotkey be empty and not actually do anything, but whenever the player changed it I would grab the keycode and save that to the variable the original code was already calling.Obviously that didn't end up working. So what I've ended up doing is effectively I have two hotkeys tied to the ability. One tied to the settings holotape, and one tied to the MCM.Whenever the player rebinds the key from one menu I disable the one associated with the other menu so that the ability doesn't get called twice on the keypress.I'm not really a fan of this method. But it's the best I could think up under the circumstances. Link to comment Share on other sites More sharing options...
Blinxys Posted December 6, 2022 Share Posted December 6, 2022 Not to jack your progress in the wrong direction, but...I have recently been struggling to bind keys in a way that is most beneficial.A LOT slips through the cracks. :unsure: However it is done, It appearws to me "F4se key codes"is the "the most desirable destination".Simple reason: Appears to take modifier keys most reliably.I think this is what allows for right and left alt and ctrl too. Without modifier key capability I would have run out of keys, or my mind a while ago. :wacko: I know nothing about the specifics, it just fits a pattern I have been observing. :geek: In fact, I'd be interested in knowing how (or having a tool) to "migrate" to f4se key codes where possible. Because some DX hooked keys don't "sense" the modifier key and fires anyway, or wishes to overwrite non-modifier hotkeys, which doesn't play out well. :mellow:i.e. hit Alt-B and it says B is already in use by: such and such Hotkey already. Seemed a right place to share. :thumbsup: Link to comment Share on other sites More sharing options...
Recommended Posts