DEKI/ENGINE 文档
手册 API 参考
deki-input 0.40.1
Deki 包参考
deki-input

输入分发和碰撞检测。将指针/触摸/按键事件分发给需要它们的组件,并读取模拟摇杆指向的方向。

仓库:github.com/dekiengine/deki-input · 最新版本:0.40.0 · 需要引擎 0.40.0 或更高版本

使用 DekiEditor --packages-add deki-input <project> 或通过包管理器安装。引擎自身的组件和 C++ API 见 Deki 文档。

在编辑器中显示为 **Input**。

组件

组件 类别 说明
I2CKeyboardComponent 输入 读取每次 I2C 读取返回一个输入字符的键盘:如 LilyGO T-Deck 的键盘、M5Stack CardKB。
InputCollider 输入 指针和触摸的点击区域。按钮和滚动组件会监听它。
TrackballComponent 输入 接在 GPIO 引脚上的轨迹球,可用作方向键和 Enter,或用作指针。

功能开关

可以从构建中去掉的部分。带有 define 的功能通过该 define 开关,其余的随其组件一起被剥离。

功能 define 默认值
Colliders DEKI_FEATURE_INPUT 开
I2C Keyboard DEKI_FEATURE_INPUT_I2C_KEYBOARD 开
Trackball DEKI_FEATURE_INPUT_TRACKBALL 开

组件参考

I2CKeyboardComponent

读取每次 I2C 读取返回一个输入字符的键盘:如 LilyGO T-Deck 的键盘、M5Stack CardKB。

检视器中的名称:I2C 键盘 · 类别:输入 · 类型:DekiInput::I2CKeyboardComponent

属性 类型 默认值 约束 说明
i2cPort int32 0 0 到 3 键盘所在的 I2C 总线。必须与设置该端口的 I2C 总线组件一致。
i2cAddress int32 85 0 到 127 键盘在总线上的地址:LilyGO T-Deck 为 0x55 (85),M5Stack CardKB 为 0x5F (95)。
hasBacklight bool false 键盘带有自行控制的背光,通过总线设置(LilyGO T-Deck 的亮度位于寄存器 0x01)。游戏代码随后可用 I2CKeyboard::SetBacklight 设置它。
reportHeldKeys bool false LilyGO T-Deck 的键盘:读取整个按键矩阵,使按键在按住期间一直处于按下状态,与桌面键盘一样。这样游戏就能在按住键时持续行走。需要带矩阵模式(寄存器 0x03)的键盘固件;关闭时,每个输入的键只按下一帧。

InputCollider

指针和触摸的点击区域。按钮和滚动组件会监听它。

检视器中的名称:输入碰撞区 · 类别:输入 · 类型:DekiInput::InputCollider

属性 类型 默认值 约束 说明
width float 0 单位 m 点击区域的宽度,单位为米。不必与绘制的内容一致。
height float 0 单位 m 点击区域的高度,单位为米。
paddingLeft float 0 单位 m 左边缘之外额外的点击区域,单位为米。可以让小控件更容易用手指点中,而不必让它看起来更大。
paddingRight float 0 单位 m 右边缘之外额外的点击区域,单位为米。
paddingTop float 0 单位 m 上边缘之上额外的点击区域,单位为米。
paddingBottom float 0 单位 m 下边缘之下额外的点击区域,单位为米。
consumeInput bool true 在此处截停按下操作,不让它传到下方的对象。对于不应遮挡后方内容的覆盖层,请关闭此项。

TrackballComponent

接在 GPIO 引脚上的轨迹球,可用作方向键和 Enter,或用作指针。

检视器中的名称:轨迹球 · 类别:输入 · 类型:DekiInput::TrackballComponent

属性 类型 默认值 约束 说明
mode enum "Keys" Keys, Pointer 按键:滚动相当于按方向键,按下相当于 Enter。指针:滚动移动指针,按下相当于鼠标按键。
pixelsPerStep int32 4 1 到 64 指针模式:球每滚动一步,指针移动多少像素
glideMs float 0 0 到 1000 指针模式:球停止后指针继续滑行的时长,单位为毫秒,类似 ThinkPad TrackPoint。0 表示严格按滚动的步数移动。
acceleration float 1 1 到 8 带滑行的指针模式:快速转动球时,每一步带动指针的距离是慢速滚动时的多少倍。1 表示不加速。
upPin int32 -1 -1 到 48 球向上滚动时产生脉冲的信号线
downPin int32 -1 -1 到 48 球向下滚动时产生脉冲的信号线
leftPin int32 -1 -1 到 48 球向左滚动时产生脉冲的信号线
rightPin int32 -1 -1 到 48 球向右滚动时产生脉冲的信号线
clickPin int32 -1 -1 到 48 按下开关(-1 = 无)
clickActiveLow bool true 按下时将引脚拉低(开),或拉高(关)

更新日志

更新日志为英文。

0.40.0

Changed

  • minEngine 0.40.0: built against engine 0.40.0. A build of this package from before does not load and is rebuilt.

Added

  • Sticks. DekiInput::GetStick(stick, &x, &y) says where an analog stick points (0 the left, 1 the right): x and y from -1 to 1, right and up positive, from the input source that has it pushed furthest. A driver reports its sticks with IDekiInput::GetStick, which reports none by default, so drivers without sticks need no change; a host feeds one through IInputSystem::DispatchStick. Sticks still send the arrow keys too, for games that only read keys.
  • DekiInput::RemoveInput(name), which shuts down and removes one input source.
  • DekiInput::BeginSession and EndSession. Everything registered after a session begins, sources and event callbacks, is removed when it ends. The editor brackets Play mode with them, so what a game adds goes when it stops.
  • Trackball::TakeRoll: how far the ball rolled since the last call, in either mode, so a game can steer with it while it moves the pointer. Trackball::Find() gets the one a TrackballComponent set up.
  • Report Held Keys on the I2C Keyboard: the LilyGO T-Deck's keyboard hands over its key matrix, so a key is down for as long as it is held and comes up when it is let go, as a desktop keyboard's does. Off by default: it needs keyboard firmware with the matrix mode (register 0x03).
  • DispatchPointer (Deki::IInputSystem): a host's pointer, in the game screen's pixels, sent as an input event from a source named "Injected pointer".

Fixed

  • A component that never started no longer silences every collider. Callback ids from RegisterEventCallback are counted from 1, and UnregisterEventCallback(0) removes nothing. Ids were positions from 0, and 0 was the input system's own callback, the one that sends pointer events to Input Colliders: a component keeping its id in a member that starts at 0, destroyed before Start (the editor does that each time it loads a scene to edit), removed it, and no collider got a tap until the editor was restarted.
  • Stopping the game and rebuilding no longer crashes the next run in IsKeyPressed. An input source the game added stayed registered after Play, and the rebuild unloaded its code.
  • In the editor, pointer events from an input source reach colliders. They were dropped because the editor runs games without Engine::Initialize.
  • A click in the editor's Play view is an input event, as a touch is on a device: RegisterEventCallback listeners hear MouseButtonDown. It used to go to the colliders only.
  • A TouchDown, TouchMove or TouchUp event reaches colliders as the matching Mouse event. No driver in the engine sends them (touch panels send Mouse events, as IDekiInput.h now says), but one of your own may.
  • UnregisterEventCallback's comment named an OnDestroy that components do not have; a listener stops in its destructor.

0.22.0

Changed

  • Translations are keyed by the editor's names with their acronyms ("I2C Port", "SPI Host" rather than "I 2c Port", "Spi Host"), which the 0.22 editor shows.
  • minEngine 0.22.0: built against engine 0.22.0. A build of this package from before does not load and is rebuilt.

更早的版本:CHANGELOG.md


由包的反射数据生成(引擎 0.40.1)。属性名就是场景文件中使用的键。重命名后会保留别名(兼容性)。