Kodi Development  20.0
for Binary and Script based Add-Ons

Detailed Description

Input operations


Hardware rendering operation parts in interface:
Copy this to your project and extend with your parts or leave functions complete away where not used or supported.

Header parts:

bool HasFeature(const std::string& controller_id, const std::string& feature_name) override;
void FreeTopology(game_input_topology* topology) override;
void SetControllerLayouts(const std::vector<kodi::addon::GameControllerLayout>& controllers) override;
bool EnableKeyboard(bool enable, const std::string& controller_id) override;
bool EnableMouse(bool enable, const std::string& controller_id) override;
bool ConnectController(bool connect, const std::string& port_address, const std::string& controller_id) override;
bool InputEvent(const game_input_event& event) override;
Definition: game.h:990
The input topology is the possible ways to connect input devices.
Definition: game.h:866
virtual bool HasFeature(const std::string &controller_id, const std::string &feature_name)
Check if input is accepted for a feature on the controller.
Definition: Game.h:675
virtual bool InputEvent(const game_input_event &event)
Notify the add-on of an input event.
Definition: Game.h:807
virtual void FreeTopology(game_input_topology *topology)
Free the topology's resources.
Definition: Game.h:703
virtual game_input_topology * GetTopology()
Get the input topology that specifies which controllers can be connected.
Definition: Game.h:692
virtual bool ConnectController(bool connect, const std::string &port_address, const std::string &controller_id)
Connect/disconnect a controller to a port on the virtual game console.
Definition: Game.h:792
virtual void SetControllerLayouts(const std::vector< kodi::addon::GameControllerLayout > &controllers)
Set the layouts for known controllers.
Definition: Game.h:716
virtual bool EnableMouse(bool enable, const std::string &controller_id)
Enable/disable mouse input using the specified controller.
Definition: Game.h:743
virtual bool EnableKeyboard(bool enable, const std::string &controller_id)
Enable/disable keyboard input using the specified controller.
Definition: Game.h:729

Source parts:

bool CMyInstance::HasFeature(const std::string& controller_id, const std::string& feature_name)
{
return false;
}
game_input_topology* CMyInstance::GetTopology()
{
return nullptr;
}
void CMyInstance::FreeTopology(game_input_topology* topology)
{
}
void CMyInstance::SetControllerLayouts(const std::vector<kodi::addon::GameControllerLayout>& controllers)
{
}
bool CMyInstance::EnableKeyboard(bool enable, const std::string& controller_id)
{
return false;
}
bool CMyInstance::EnableMouse(bool enable, const std::string& controller_id)
{
return false;
}
bool CMyInstance::ConnectController(bool connect, const std::string& port_address, const std::string& controller_id)
{
return false;
}
bool CMyInstance::InputEvent(const game_input_event& event)
{
return false;
}

Modules

 Group header include
 
 Group source include
 

Function Documentation

◆ HasFeature()

virtual bool HasFeature ( const std::string &  controller_id,
const std::string &  feature_name 
)
inlinevirtual

Check if input is accepted for a feature on the controller.

If only a subset of the controller profile is used, this can return false for unsupported features to not absorb their input.

If the entire controller profile is used, this should always return true.

Parameters
[in]controller_idThe ID of the controller profile
[in]feature_nameThe name of a feature in that profile
Returns
true if input is accepted for the feature, false otherwise

◆ GetTopology()

virtual game_input_topology* GetTopology ( )
inlinevirtual

Get the input topology that specifies which controllers can be connected.

Returns
The input topology, or null to use the default

If this returns non-null, topology must be freed using FreeTopology().

If this returns null, the topology will default to a single port that can accept all controllers imported by addon.xml. The port ID is set to the DEFAULT_PORT_ID constant.

◆ FreeTopology()

virtual void FreeTopology ( game_input_topology topology)
inlinevirtual

Free the topology's resources.

Parameters
[in]topologyThe topology returned by GetTopology()

◆ SetControllerLayouts()

virtual void SetControllerLayouts ( const std::vector< kodi::addon::GameControllerLayout > &  controllers)
inlinevirtual

Set the layouts for known controllers.

Parameters
[in]controllersThe controller layouts

After loading the input topology, the frontend will call this with controller layouts for all controllers discovered in the topology.

◆ EnableKeyboard()

virtual bool EnableKeyboard ( bool  enable,
const std::string &  controller_id 
)
inlinevirtual

Enable/disable keyboard input using the specified controller.

Parameters
[in]enableTrue to enable input, false otherwise
[in]controller_idThe controller ID if enabling, or unused if disabling
Returns
True if keyboard input was enabled, false otherwise

◆ EnableMouse()

virtual bool EnableMouse ( bool  enable,
const std::string &  controller_id 
)
inlinevirtual

Enable/disable mouse input using the specified controller.

Parameters
[in]enableTrue to enable input, false otherwise
[in]controller_idThe controller ID if enabling, or unused if disabling
Returns
True if mouse input was enabled, false otherwise

◆ ConnectController()

virtual bool ConnectController ( bool  connect,
const std::string &  port_address,
const std::string &  controller_id 
)
inlinevirtual

Connect/disconnect a controller to a port on the virtual game console.

Parameters
[in]connectTrue to connect a controller, false to disconnect
[in]port_addressThe address of the port
[in]controller_idThe controller ID if connecting, or unused if disconnecting
Returns
True if the controller was (dis-)connected to the port, false otherwise

The address is a string that allows traversal of the controller topology. It is formed by alternating port IDs and controller IDs separated by "/".

For example, assume that the topology represented in XML for Snes9x is:

<logicaltopology>
<port type="controller" id="1">
<accepts controller="game.controller.snes"/>
<accepts controller="game.controller.snes.multitap">
<port type="controller" id="1">
<accepts controller="game.controller.snes"/>
</port>
<port type="controller" id="2">
<accepts controller="game.controller.snes"/>
</port>
...
</accepts>
</port>
</logicaltopology>

To connect a multitap to the console's first port, the multitap's controller info is set using the port address:

1

To connect a SNES controller to the second port of the multitap, the controller info is next set using the address:

1/game.controller.multitap/2

Any attempts to connect a controller to a port on a disconnected multitap will return false.

◆ InputEvent()

virtual bool InputEvent ( const game_input_event event)
inlinevirtual

Notify the add-on of an input event.

Parameters
[in]eventThe input event
Returns
true if the event was handled, false otherwise

◆ KodiInputEvent()

bool KodiInputEvent ( const game_input_event event)
inline

Callback to Kodi Function
Notify the port of an input event

Parameters
[in]eventThe input event
Returns
true if the event was handled, false otherwise
Note
Input events can arrive for the following sources:
  • GAME_INPUT_EVENT_MOTOR
Remarks
Only called from addon itself