About this mod
Prompt the user for textual input, and get back what they type. Basically, an input box for Skyrim.
- Requirements
- Permissions and credits
As an added bonus, capitalization is respected while the user is typing, and will be retained by your code unless what the user types is an exact match for a string that the Skyrim engine has already seen.
Using KeyInput is incredibly easy:
scriptname Example extends ReferenceAlias
KeyInput property user_input auto
event GotInput(bool accepted, string value)
if accepted
Debug.Notification(value)
endif
endevent
event OnPlayerLoadGame()
RegisterForSingleUpdate(5.0)
endevent
event OnUpdate()
RegisterForModEvent("GotInput", "Example_GotInput")
user_input.GetInput("What is your favorite color?", "Example_GotInput")
endevent
All you have to do is:
- Create a Quest
- Attach the KeyInput script to it
- Bind the quest to a property (or use SKSE's Quest.GetQuest function) so it's accessible in the place where you want to prompt the user for input
- Register for a user event (named whatever you like)
- Call GetInput with the prompt and the name of the event you've chosen
The event will be triggered when the user is finished. If the user cancelled the input, the first event parameter will be false, otherwise it will be true. Either way, the second parameter will be what the user typed.
The keymap is configurable, and your code can select among the available keymaps at runtime by passing the keymap filename as a third parameter to GetInput. The default keymap is for US qwerty keyboards, but the system was designed to be i18n friendly. UTF8 characters in keymaps are fully supported, and customized input methods and chording are possible.
The SWF file used for interacting with the user is selectable at runtime, so you can replace it with one that matches your mod's user interface. A simple but functional default is provided, along with source code which you can use as a basis for your own. To make your own skin, all you have to do is create a Flash file that has an update(prompt:String, value:String) function in the _root namespace, which when called updates the displayed text. Everything else is up to you.
Permission:
Obviously, KeyInput is intended to be used as a component of other mods. You may bundle it with your own mod if you choose, but I would prefer that you instead use this mod as a dependency, to avoid situations where an older mod overwrites a newer KeyInput on install.