Jump to content

[1.1](Apr24/16) Control Lock: Input text into text fields without issuing commands to your vessel


Diazo

Recommended Posts

Dead mod: KSP's UI revamp in 1.1 has closed the loophole that required this mods presence. As such this mod is officially dead and no longer supported.

 

Control Lock

Found on the CKAN as Control Lock

Input text into text entry fields without issuing commands to your vessel.

Works in all game scenes.

When engaged, base KSP commands do not respond to input.

This allows you to safely type into text fields without activating vessel commands.

Note this also includes clicking on things, no more clicking through mod windows in the space center and changing scene and no more accidentally picking up parts when you click through a window in the editor.

Download here.

License: Unlicense (Public Domain) Specifically intended to allow bundling with your own mod, see note below on how to do this.

Source: GitHub

Displays on Blizzy's toolbar if installed, otherwise on the Stock toolbar.

Updated for KSP 1.1, however I am no longer sure this mod is needed after the GUI overhaul as this mod deals with issues in the old GUI. However, as I do not have a Linux system available I am unable to test it myself. If you are on Linux, please let me know if this mod is still needed.

For Players:

The icon for this mod is the letters AZ with an X through them.

Left click the icon on the toolbar to lock your controls, the icon will change to a yellow border.

Left click the icon again to re-enable your flight controls. The icon will revert to having no border.

If the icon has a red border, that means a mod has hooked into this mod and is locking your controls. Ensure there is not something like a kOS terminal window that currently has focus.

If desired, a Hotkey can be setup to also trigger the lock. (No key is assigned by default.)

To do so, right click on the icon to show the keybind screen. Click the button and then press the key to assign.

Note that keys bound to this do not prevent fall through, if you assign LeftAlt-V to this mod, every time you engage it you will also toggle a camera change on the V keypress.

The same lock is engaged by hotkey and mouse click, watch for the yellow border on the icon to tell the state of the lock.

When the lock on your controls is engaged, the only key KSP will recognize is the Escape key to bring up the menu to allow you to change scenes in case the lock gets stuck.

On scene change the lock is disabled.

You engage/disengage the lock yourself by clicking the icon, for the lock to automatically activate for things such as a kOS terminal window, you will have to talk to the mod developer and have them incorporate it.

Note that you can override other mods enabled ControlLock by right clicking to open the Control Lock window and clicking the RESET button, this will clear all locks and return controls to normal.

(At this time kOS does not actually support this mod, I am using their terminal window as an example.)

This allows for text input for things such as kOS's terminal window, or the name field when renaming a vessel, and use keys such as Z or X without affecting your throttle.

Note that this is base KSP only, this mod does not block commands to any mods using those keys.

Mods known to use this mod:

Action Groups Extended: Will not activate action groups via keyboard when Control Lock is engaged.

For Mod Developers (Engage control lock from your mod):

Under the Unlicense, you have specific permission to redistribute this mod bundled in your mod's .zip file. Note that to keep the icon from messing up and for interoperability with other mods it needs to stay at GameData\001ControlLock.

Note the 001 prefix on the mod folder, this means that you can create a hard dependency on this mod and do not need to mess with reflection.

The following methods are exposed:

 

 
SetFullLock(string)
UnsetFullLock(string)
IsLockSet()
IsLockSet(string)

 

SetFullLock: Pass this method a string, I recommend the name of your mod, to engage the lock. Note you can pass the same lock multiple times, this mod will detect that and only lock controls the first time the mod is locked after being unlocked.

UnsetFullLock: Pass the name of your control lock to unset the lock. This is the same string (capitilization matters) that you passed in the SetFullLock command. It is safe to pass this with an invalid string, nothing will happen.

IsLockSet(): Check if the control lock is set, yes or no.

IsLockSet(string): Is the control lock set by a specific mod? The string is the same string as passed to SetFullLock. Note that this method can return false that it is not locked by a mod, but another mod is enforcing the control lock.

Note that this mod only locks once per text string passed to it. If you issue SetFullLock("MyModLock") 5 times, a single issue of UnsetFullLock("MyModLock") will unlock the controls. If you need to keep track of the number of locks, pass SetFullLock("MyModLock1") and SetFullLock("MyModLock2"), the mod will only unlock the controls after both UnsetFullLock("MyModLock1") and UnsetFullLock("MyModLock2") have been passed to it.

Also, to avoid conflicts, everyone must make a dependancy and use the mod as provided. If you copy-paste the code into your own mod you will break things as this mod and your mod will not be aware of each other's lock/unlocks and probably cause the player's keybinds to go weird.

Note that everything is also available via reflection, I'll get the code for that up when I get a free minute.

For Mod Developers (Monitor control lock only):

To keep things simple, this mod also sets KSP's input lock via the InputLockManager class. That means you do not have to assign this mod as a dependancy or mess with reflection.

I recommend using the ControlTypes.KSC_ALL value to check if this mod is engaged or not, although most controltypes can be used. Note that ControlTypes.GUI .MainMenu .AppLauncher_Buttons .KSC_UI and .Pause are not locked by this mod.

 

 
if ((ControlTypes.KSC_ALL & (ControlTypes)InputLockManager.lockMask) == 0)
                {
                       code to run when control lock is NOT engaged.
                       switch == above to != to run code when lock IS engaged.
                } 

 

Let me know how it goes,

D.

Edited by Diazo
Link to comment
Share on other sites

Glad to hear this looks to be what people were looking for. :)

My one concern would be on where I interface to KSP's built in control lock manager. I simply told it to "lock all".

However, "lock all" includes values such as "Editor_UI" which I think is locking the editor buttons so they can't be moused clicked.

I don't actually know however so I'm asking people that if they come across something that got locked by this that shouldn't be, let me know so I can remove the lock on that part of the game.

Happy KSPing everyone.

D.

edit: I just did some experiments and will be leaving the "lock all" as it currently is set. This has the advantage of stopping you from clicking through a mod's GUI windows so if this mod is engaged you can't click through to a building in the Space Center and change scene and in the editor you can't accidentally pick up parts by clicking through a window. Note right-clicking on a part still opens a part's right-click menu however, the lock does not affect that.

Edited by Diazo
Link to comment
Share on other sites

Version 1.2

Download.

Just a quick fix for a mis-labeling in the code from Squad.

The stock toolbar (a.k.a. the appLauncher) is not locked by the ControlTypes.AppLauncher_Buttons, but rather by the ControlTypes.GUI flag. This is mainly a quick fix so that you can actually disable this mod after enabling it on the stock toolbar.

Version 1.1 would actually lock the toolbar out, so when you clicked it KSP ignored the input so you could never disable the mod. (Blizzy's toolbar did not have this issue.)

Now fixed, everything should be good to go.

D.

Link to comment
Share on other sites

Awesome!! Can't wait to try this out - the number of times I've throttled-up my space stations while renaming docking ports (and hence zooming off into the black beyond, leaving my cargo ship lonley in orbit) is beyond count..

Will you be adding this to CKAN?

Oh, and another (semi-unrelated) thing, I was just about to lodge a bug against KSP about this. By the comments above, this issue is Linux-specific? Has it been raised and is Squad aware?

Link to comment
Share on other sites

Oh, and another (semi-unrelated) thing, I was just about to lodge a bug against KSP about this. By the comments above, this issue is Linux-specific? Has it been raised and is Squad aware?

AFAIK - the issue is related to Unity3d on Linux - Squad and some KSP modders implement their own work arounds but as we know - it is still easy to accidentally cause havok with key presses intended for a specific window.

There is possibly no way for Squad to fix it and have all modders re-use the methods for their own GUI's.

Link to comment
Share on other sites

@CKAN: I have submitted this to the CKAN, but it looks like I had a typo that kept it from showing. I've fixed the typo and it should show up soon.

@The Error: This mod actually fixes two things.

First, on all platforms, SQUAD offers an "Input Control Lock" for modders so they can prevent keystrokes from being recognized while their mod has focus. Except SQUAD did not add the throttle keys to this control lock so that even if you engage this in-game lock, touching a throttle key still behaves as normal. (Such as the kOS or RemoteTech terminal windows.) Our best guess is Squad wanted to make sure players had an emergency method to avoid a crash while the lock was engaged, but at this point leaving the throttle keys out of the lock has caused more crashes then it has prevented.

Second, on Linux only, when you give focus to a text box, that text box does not prevent keystrokes from falling through to KSP and executes them as game commands. So any mod that allows you to enter text would cause your vessel to spaz out when you typed as pretty much every key on the keyboard is assigned to something.

This mod fixes both of these issues by actually going into the settings and un-binding all keys (except ESC for the game menu) when engaged and then rebinding them when the control lock is disabled. (Or rebinding them the next time the game starts if there was a crash while the keys were unbound.)

D.

Link to comment
Share on other sites

One place where this would be very useful is when running the DMP multiplayer mod. It has a chat window for you to talk to the other players, but rather annoyingly it's set up in such a way that the chat window loses keyboard focus whenever the DMP system prints out a system notification to the chat window, which can happen any time a player joins or leaves the server. As these are not events under your own control, that happen "randomly" as far as you can control, it's very annoying the effect this has on the game. You type a sentence with spaces in it like "hello, everybody, come see this neat thing I made" into the chat and partway through typing it a player joins the game making the chat window print the join message, and steal focus away from the typing line. If you don't IMMEDIATELY notice this and stop your finger within about 0.1 seconds as it was on the way down to the next key, you're now controlling the craft, staging it when you hit spacebar, and so on.

It's not *quite* the problem the mod was designed for (the inability to lock out certain keys in KSP is different from a mod author *choosing* to steal focus from the chat window on an async event like a player-join), but it's a good workaround for it anyway.

Link to comment
Share on other sites

@Steven Mading: My DMP was set off :D

And yeah, this is linux-specific and *freaking* annoying.

I think I can work around that issue you mentioned though, I suspect unity is holding an integer of the active element ID, and when a new label (message) comes in it bumps it out one which deselects it. I'll poke that bug for you.

Link to comment
Share on other sites

  • 3 weeks later...
@Steven Mading: My DMP was set off :D

And yeah, this is linux-specific and *freaking* annoying.

I think I can work around that issue you mentioned though, I suspect unity is holding an integer of the active element ID, and when a new label (message) comes in it bumps it out one which deselects it. I'll poke that bug for you.

Definitely looking forward to this fix -- accidentally jettisoning my SSTO's cargo during liftoff while trying to coordinate a rendezvous with other players in chat is not fun... lol

Hasn't this bug been around pretty much since the start of DMP??

Diazo - Awesome mod. One of the very few I have installed on all my copies of KSP. Great work.

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

Version 1.3

Download here.

-Add hotkey support.

As of this version, you must left click the icon to engage the control lock

Right clicking the icon now opens the keybind window to assign a hotkey if you wish.

There is no hotkey assigned by default and note that the keybind window can not be dragged around the screen.

You can assign just a key or a key combination with the modifier key. Note that any key can be assigned to either role, so a combination of V-LeftAlt is valid (hold V while pressing LeftAlt) as well as the more typical LeftAlt-V (hold LeftAlt and press V).

Special Keys such as Escape and the F1-F12 keys, as well as joystick buttons, should be valid "keys" for assigning to this window.

Note that mouse buttons can not be assigned to either role due to limitations in the input code.

Also, key fall though is not prevented, if you use the example LeftAlt-V above, every time you trigger the control lock, you will be changing the camera on the V press as well.

As always, feedback is appreciated.

D.

Link to comment
Share on other sites

  • 3 weeks later...

Version 1.4

KSP 1.0 Update. (KSP 1.0.2 also.)

No functionality changes visible to the player, but the KSP update does break this mod.

Therefore, KSP 0.90 must use version 1.3 of this mod, KSP 1.0 must use version 1.4.

D.

Edited by Diazo
Link to comment
Share on other sites

  • 3 weeks later...

Hey there, whish I had this mod way earlier, as many plus many stuff conflicted while trying to input data.

Though it seems that on recent version of mods people have been implementing the click through prevention (I think something already built-in in Unity).

Anyway, don't if its actually your mod doing that or not.

But I've been getting some issues, specifically, lots of lag and hiccups occurring when trying to edit RemoteTech window in map view, works normally in flight scene.

Just wanted to know if someone experienced this. Clicking the control lock restores to normal, I can input data etc.

I've checked the log and indeed RT seems to use this (and is the only one currently). Any advice?

Link to comment
Share on other sites

Hey there, whish I had this mod way earlier, as many plus many stuff conflicted while trying to input data.

Though it seems that on recent version of mods people have been implementing the click through prevention (I think something already built-in in Unity).

Anyway, don't if its actually your mod doing that or not.

But I've been getting some issues, specifically, lots of lag and hiccups occurring when trying to edit RemoteTech window in map view, works normally in flight scene.

Just wanted to know if someone experienced this. Clicking the control lock restores to normal, I can input data etc.

I've checked the log and indeed RT seems to use this (and is the only one currently). Any advice?

Hi Gfurst, Dennis from RemoteTech here. Can you please send me your log file (via pm) that i can see what happens. I just tried ControlLock with RT and i got no lag.
Link to comment
Share on other sites

Hi Gfurst, Dennis from RemoteTech here. Can you please send me your log file (via pm) that i can see what happens. I just tried ControlLock with RT and i got no lag.

Alright, I'll do a quick test when a can so to keep the log clean. Will post on the RT thread too, if that makes more sense.

Link to comment
Share on other sites

Alright, I'll do a quick test when a can so to keep the log clean. Will post on the RT thread too, if that makes more sense.

Thanks Gfurst but i can reproduce this issue, and it's not the ControlLock-Mod. Something is different between the InputLockManager from FlightMode and Mapview :huh: i'll look into it.

Link to comment
Share on other sites

  • 2 weeks later...

Hey bro. Really nice mod. Works wonders, but I have a suggestion, if I may. How about a mouse-drag lock for when Kerbals are EVA? This would be most useful with the new Kerbal Inventory System, when users have to drag items around different inventories. Having the ability to mouse lock while maintaining the ability to adjust your EVA motion would be immensely useful.

Edited by IRnifty
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...