IInput: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Added categories)
m (Setting bug notice hidetested=1 param on page where the bug might not need tested in param specified)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
This interface is used by the Source Engine to access input functionality that must be implemented in game code. This class handles mouse and joystick input, keeps track of and modifies key "button" state, and completely controls the position of the camera. The file iinput.h should remain unedited as the engine expects to find the IInput interface as it is currently presented in iinput.h. To implement IInput the game code creates a new class inheriting IInput, and exposing it to engine:
'''<code>IInput</code>''' is a client [[interface]] that packages user input from keyboards, mice and joysticks/gamepads into [[usercmd]]s for transmission to the server. It also handles [[third-person camera]]s.


class CMyInput : public CInput
Conventionally, each type of supported peripheral has its own CPP file. Valve's <code>[[CInput]]</code> interface implementation is in <code>in_main.cpp</code> (for usercmd packaging and keyboard), <code>in_mouse.cpp</code> and <code>in_joystick.cpp</code>.
{
public:
};
static CMyInput g_Input;
// Expose this interface
IInput *input = ( IInput * )&g_Input;


The easiest way to implement this interface is by starting with and modifying the preexisting class CInput. CInput is declared in input.h and is implemented in:
== Minimum implementation ==


* in_main.cpp
<source lang=cpp>static CInput g_Input;
* in_mouse.cpp
IInput* input = (IInput*)&g_Input;</source>
* in_camera.cpp
* in_joystick.cpp


[[Category:Programming]][[Category:Interfaces]]
{{bug|hidetested=1|Although your mod will compile fine if you bypass creating the <code>g_Input</code> object, you may encounter bizarre errors (including the world not rendering and a cursor that is re-centred every frame) when launching with a debugger attached!}}
 
== See also ==
 
* <code>[[CInput]]</code>, Valve's basic <code>IInput</code> implementation
 
[[Category:Interfaces]]

Latest revision as of 07:14, 20 May 2025

IInput is a client interface that packages user input from keyboards, mice and joysticks/gamepads into usercmds for transmission to the server. It also handles third-person cameras.

Conventionally, each type of supported peripheral has its own CPP file. Valve's CInput interface implementation is in in_main.cpp (for usercmd packaging and keyboard), in_mouse.cpp and in_joystick.cpp.

Minimum implementation

static CInput g_Input;
IInput* input = (IInput*)&g_Input;
Icon-Bug.pngBug:Although your mod will compile fine if you bypass creating the g_Input object, you may encounter bizarre errors (including the world not rendering and a cursor that is re-centred every frame) when launching with a debugger attached!

See also

  • CInput, Valve's basic IInput implementation