I want to be able to set in-game key binds in a custom inspector. I am currently doing a non-custom inspector with a public keycode variable showing a dropdown menu of all possible keys. I’d like to make this cleaner. To do this, I’d like to be able to have some kind of field that has the following behavior:
a user clicks it to select it
the user presses a key
the code records the keycode of the key pressed, and then the control is deselected
I can’t seem to figure out how to do this. I know there are text fields that can be used to enter text, but it seems to me that is not the functionality I want.
The editor is criminally under-documented. Thank you for that find, though. I didn’t think that anyone had taken the time to do a proper primer on the EditorGUI system before.
I fixed one bug that didn’t allow it to play nicely with other controls in the inspector. Also, this doesn’t capture any “shift” key down. I’m trying to figure out a workaround for that. It might involve designing a custom inspector that uses this control and that provides the option to set keys that are not actually available in the hardware the person using this has. This is probably necessary for cross-platform stuff.
Here is a thread that discusses the shift key issue:
Apparently the shift key issue is a decade-old bug (not kidding!) and still hasn’t been fixed.