Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Handling Input

JoshSnider edited this page Apr 19, 2018 · 5 revisions

A handler callback function for the on_input callback might look something like this:

void handle_interactive_input(void* context, interactive_session session, const interactive_input* input)
{
    ...
}

The first parameter, context is a pass-through parameter that your code may set in order to retain context between calls since C++ lambda functions may not be used with this C-style interface that uses function pointers. The second parameter is the current session that you may use to make subsequent calls and the final parameter is a pointer to an interactive_input struct.

Input types

There are currently 4 input types.

  • input_type_key - When a keyboard shortcut key is used to send a button action.
  • input_type_click - When a mouse or other pointer (perhaps touch input) is used to send a button action.
  • input_type_move - When a mouse or other pointer moves within a control such as a joystick.
  • input_type_custom - Any other type of input.

Handling joystick input

You might handle joystick input like this:

if ((input_type_key == input->type || input_type_click == input->type) && interactive_button_action_down == input->buttonData.action)
{
	// Capture the transaction on button down to deduct the viewer's sparks before executing any game functionality.
	controlsByTransaction[input->transactionId] = input->control.id;
	std::cout << participantName << " clicked '" << input->control.id << "'. Deducting sparks..." << std::endl;
	err = interactive_capture_transaction(session, input->transactionId);
	if (err)
	{
		std::cerr << "Failed to capture interactive transaction." << std::endl;
	}
}
Clone this wiki locally