📂
Bannerlord Modding CN
  • 骑马与砍杀2 领主 Mod 制作文档
  • C# API Documentation
    • Core
      • MBObjectManager
      • GameModel
      • InformationManager
      • BasicCharacterObject
      • Game
      • ItemObject
    • Campaign System
      • GameMenu
      • Settlement
      • CampaignGameStarter
      • actions
        • ChangeOwnerOfSettlementAction
      • TournamentGame
      • Hero : MBObjectBase, ITrackableCampaignObject, ITrackableBase
      • CampaignBehaviorBase
    • Mount And Blade
      • MissionBehaviour
        • MissionView
        • MissionLogic
      • MBInitialScreenBase
      • Mission
      • MBSubModuleBase
      • agent
      • Team
    • Input System
      • Input
    • Engine
      • GlobalLayer
      • ScriptComponentBehaviour
      • Scene
      • GameEntity
    • Library
      • ModuleInfo
    • Platform Service
    • Save System
    • Localization
      • MBTextManager
      • TextObject
    • Network
    • Two Dimension
  • XML Documentation
    • NPCCharacters
      • NPCCharacter(NPC角色)
        • upgrade_targets
          • upgrade_target
        • equipmentSet
          • equipment
        • Face
          • BodyProperties
          • hair_tags
            • hair_tag
          • BodyPropertiesMax
          • beard_tags
            • beard_tag
          • face_key_template
        • equipment
        • skills
          • skill
        • Traits
          • Trait
    • 物品(大类) Items
      • 物品 Item
        • 物品组件 ItemComponent
          • 马匹 Horse
            • Materials
              • Material
                • MeshMultipliers
                  • MeshMultiplier
          • 防具 Armor
          • Weapon
            • WeaponFlags
          • 食物 Food
        • 旗帜 Flags
      • CraftedItem
        • Pieces
          • Piece
    • Items (XML)
    • Scenes
      • Scene
        • GameType
        • TerrainType
          • TerrainType
    • SPCultures (XML)
    • SPCultures
      • Culture
        • female_names
          • name
        • male_names
          • name
        • clan_names
          • name
    • Atmosphere (XML)
    • SubModule (XML)
    • Scenes (XML)
    • NPCCharacters (XML)
  • Gauntlet
    • Brush
    • GauntletLayer
    • GauntletMovie
    • SceneLayer
    • Movie (XML)
    • Widget
    • GauntletView
    • ScreenBase
    • ViewModel
    • ScreenManager
  • Introduction
    • 高级用法
    • 开始第一步
    • 文件夹结构
    • Defining custom data
  • Tutorials
    • 将你的mod打包上传至Vortex
    • Making Banners
    • 不需要C#的UI系统Mod入门 #
    • 基本 C# Mod
    • new_settlements
  • ru
    • _intro
      • Начало
      • Структура папок
Powered by GitBook
On this page
  • Key Reading
  • public static bool Input.IsKeyDown(InputKey key)
  • public static bool Input.IsKeyDownImmediate(InputKey key)
  • public static bool Input.IsKeyPressed(InputKey key)
  • public static bool Input.IsKeyReleased(InputKey key)
  • public static bool Input.IsControlOrShiftNotDown()
  • public static bool Input.IsPressed(InputKey key)
  • public static Vector2 Input.GetKeyState(InputKey key)
  • public static string Input.GetKeyboardText()
  • public static bool Input.IsMouseActive
  • public static bool Input.IsMouseScrollChanged
  • public static float Input.MouseMoveX
  • public static float Input.MouseMoveY
  • Examples
  • Monitoring a key's state
  • Key Codes

Was this helpful?

  1. C# API Documentation
  2. Input System

Input

PreviousInput SystemNextEngine

Last updated 4 years ago

Was this helpful?

Input这个静态类型用来提供输入功能。基本的输入系统并不是基于事件绑定的,而是采用轮询的方式。这部分内容比较直观,一般来说看函数名就知道用法,但也会有几个坑。

Key Reading

There's a number of useful methods that detect keys being pressed down in different ways, all seeming to return a 'bool'. Most common are IsKeyDown, IsKeyPressed and IsKeyReleased

You can call them like so: Input.IsKeyDown(InputKey.TheKeyCode). See here for a list of all keycodes:

You can also use the extension methods IsDown/IsPressed/IsReleased as such KeyCode.A.IsPressed()

Below, you may find an in-depth documentation of each.

Namespace

This page assumes an import like so: using TaleWorlds.InputSystem;

public static bool Input.IsKeyDown( key)

This checks to see if the specified [key] is currently being pressed, it returns true as long as the [key] is held down.

Example:

   if(Input.IsKeyDown(InputKey.Y))
   {

       //doSomething

   }

This acts as an intermediary check between IsKeyDown and IsKeyPressed

Example:

    if(Input.IsKeyDownImmediate(InputKey.Y))
    {

        //doSomething

    }

This checks to see if the specified [key] has been pressed, it returns a bool once.

Example:

    if(Input.IsKeyPressed(InputKey.Y))
    {

        //doSomething

    }

This checks to see if the specified [key] is not currently being pressed, it returns a bool once.

Example:

    if(Input.IsKeyReleased(InputKey.Y))
    {

        //doSomething

    }

public static bool Input.IsControlOrShiftNotDown()

I do not believe there is any other method more self-explanatory than this. Returns true while neither Control or Shift are down.

Checks to see if a they specified [key] is currently pressed. Unlike IsDown, it can be used as Input.IsPressed() but not as an extension.

Checks and returns the current state of the specified [key] as a Vector2. I am not aware how this can be used.

Example:

  using System.Numerics; // WARNING, this assumes the existance of System.Numerics.Vectors.dll,
                         // which has to be installed manually.
  using Taleworlds.InputSystem;

  Vector2 test = new Vector2(Input.GetKeyState(InputKey.A));

  Vector2 compare = new Vector2(10, 10);

  if (Equals(test, compare))
    InformationManager.DisplayMessage(new InformationMessage("Help please I'm forced to write this doc!"));

public static string Input.GetKeyboardText()

Returns the text currently existing in the user's clipboard as a string.

public static bool Input.IsMouseActive

Checks to see if the mouse is currently active, if so returns true.

public static bool Input.IsMouseScrollChanged

Checks to see if the mouse scroll wheel is currently rotating, if so returns true.

public static float Input.MouseMoveX

Returns the horizontal position of the mouse as a float.

public static float Input.MouseMoveY

Returns the vertical position of the mouse as a float.

Examples

Monitoring a key's state

  protected override void OnApplicationTick(float dt)
  {
    int x = 0;
    int y = 0;
    int z = 0;
    //If X has been pressed, increment x by 1
    if(Input.IsKeyPressed(InputKey.X))
      x++;
    //For each tick that X is being held down, increment y by 1
    if(Input.IsKeyDown(InputKey.X))
      y++;
    //For each tick that X is untouched, increment z by 1
    if(Input.IsKeyReleased(InputKey.X))
      z++;
  }

Key Codes

As of Bannerlord 1.2.1 the following key codes are available:

public enum InputKey
{
    Invalid,
    Escape,
    D1,
    D2,
    D3,
    D4,
    D5,
    D6,
    D7,
    D8,
    D9,
    D0,
    Minus,
    Equals,
    BackSpace,
    Tab,
    Q,
    W,
    E,
    R,
    T,
    Y,
    U,
    I,
    O,
    P,
    OpenBraces,
    CloseBraces,
    Enter,
    LeftControl,
    A,
    S,
    D,
    F,
    G,
    H,
    J,
    K,
    L,
    SemiColon,
    Apostrophe,
    Tilde,
    LeftShift,
    BackSlash,
    Z,
    X,
    C,
    V,
    B,
    N,
    M,
    Comma,
    Period,
    Slash,
    RightShift,
    NumpadMultiply,
    LeftAlt,
    Space,
    CapsLock,
    F1,
    F2,
    F3,
    F4,
    F5,
    F6,
    F7,
    F8,
    F9,
    F10,
    Numpad7,
    Numpad8,
    Numpad9,
    NumpadMinus,
    Numpad4,
    Numpad5,
    Numpad6,
    NumpadPlus,
    Numpad1,
    Numpad2,
    Numpad3,
    Numpad0,
    NumpadPeriod,
    Extended,
    F11,
    F12,
    NumpadEnter,
    RightControl,
    NumpadSlash,
    RightAlt,
    NumLock,
    Home,
    Up,
    PageUp,
    Left,
    Right,
    End,
    Down,
    PageDown,
    Insert,
    Delete,
    ControllerLStick,
    ControllerRStick,
    LeftMouseButton,
    RightMouseButton,
    MiddleMouseButton,
    X1MouseButton,
    X2MouseButton,
    MouseScrollUp,
    MouseScrollDown,
    ControllerLStickUp,
    ControllerLStickDown,
    ControllerLStickLeft,
    ControllerLStickRight,
    ControllerRStickUp,
    ControllerRStickDown,
    ControllerRStickLeft,
    ControllerRStickRight,
    ControllerLUp,
    ControllerLDown,
    ControllerLLeft,
    ControllerLRight,
    ControllerRUp,
    ControllerRDown,
    ControllerRLeft,
    ControllerRRight,
    ControllerLBumper,
    ControllerRBumper,
    ControllerLOption,
    ControllerROption,
    ControllerLThumb,
    ControllerRThumb,
    ControllerLTrigger,
    ControllerRTrigger,
}

public static bool Input.IsKeyDownImmediate( key)

public static bool Input.IsKeyPressed( key)

public static bool Input.IsKeyReleased( key)

To see how one could document the stages of a key using the above 3 methods:

public static bool Input.IsPressed( key)

public static Vector2 Input.GetKeyState( key)

link
InputKey
InputKey
InputKey
InputKey
example
InputKey
InputKey