Jump to content

How to Overwrite Game Key Bindings?


Recommended Posts

I'm working on a mod that allows you to lock a key so you don't have to hold it down physically. For example if I press W and Insert (the key that activates the lock which I will probably change later) is will continue to pitch down until I hit the home key (again, just a key that wasn't being used by the game.) This is my goal at least. The problem is when I do this, the W key takes its main purpose and stops pitching when I let go. I've tested out other keys that are not being used and my plugin does work. How do I tell the game to use my command for a key as oppose to the default one?

public void UpdateLockKeyPitchUp()        
{
if (Input.GetKeyDown(KeyCode.S) && Input.GetKeyDown(KeyCode.Insert))


FlightGlobals.ActiveVessel.OnFlyByWire += LockKeyPitchUp;
if (Input.GetKeyDown(KeyCode.Home))


FlightGlobals.ActiveVessel.OnFlyByWire -= LockKeyPitchUp;
}

Earlier I have this code:

public void LockKeyPitchUp(FlightCtrlState state)        
{
{ state.pitch = 1; }
}

Edited by Ulico
Link to comment
Share on other sites

The issue is that your code is never triggering.

Input.GetKeyDown is only True for a single update frame so even though you are holding the key down, .GetKeyDown is false. As you physically can't press the keyboard keys within the same 1/50th of a second (how long a single update frame lasts) your IF statement never triggers.

You need to use .GetKey on the Insert check as .GetKey is true as long as the key is held down.

When checking modified inputs like this, modifier keys need to all use .GetKey while only the main key gets .GetKeyDown.

If you need an example I do this in AGX and can dig up the code for you.

D.

Link to comment
Share on other sites

The issue is that your code is never triggering.

Input.GetKeyDown is only True for a single update frame so even though you are holding the key down, .GetKeyDown is false. As you physically can't press the keyboard keys within the same 1/50th of a second (how long a single update frame lasts) your IF statement never triggers.

You need to use .GetKey on the Insert check as .GetKey is true as long as the key is held down.

When checking modified inputs like this, modifier keys need to all use .GetKey while only the main key gets .GetKeyDown.

If you need an example I do this in AGX and can dig up the code for you.

D.

Thanks, I'll try this out later.

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...