KeyInput by djarb
Skyrim » Modders Resources and Tutorials
Added: 09/08/2014 - 10:40PM
Updated: 14/08/2014 - 05:59PM

7 Endorsements

1.0.1 Latest version

102 Unique D/Ls

154 Total D/Ls

8,356 Total Views

Uploaded by djarb


Last updated at 17:59, 14 Aug 2014 Uploaded at 22:40, 9 Aug 2014

The ability to request textual input is a feature that has been sorely lacking from the Skyrim engine. No more! Modders, rejoice, because you can now easily ask the player questions, and get back arbitrary text answers.

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

event OnPlayerLoadGame()

event OnUpdate()
RegisterForModEvent("GotInput", "Example_GotInput")
user_input.GetInput("What is your favorite color?", "Example_GotInput")

All you have to do is:
  1. Create a Quest
  2. Attach the KeyInput script to it
  3. 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
  4. Register for a user event (named whatever you like)
  5. 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.

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.