SteamVR/Environments/Scripting/API/CDestinationsPropTool.OnHandleInput

From Valve Developer Community
Jump to navigation Jump to search

Function Description

table OnHandleInput(table input)

Adding this function to the entity script of a prop_destinations_tool causes it to be called periodically by the game while the tool is held. A table of motion controller inputs associated with the hand using the tool is passed to the function. Modifying the table and returning it allows for capturing inputs making the game code ignore them.


Example
-- Note that the m_nHandID variable is the current hand ID, and needs to be set from the SetEquipped() function.

function OnHandleInput( input ) 
 	-- this is lua's ugly version of a ternary operator
 	-- we do this because we only care about the input from the hand that is holding us
 	-- but you could check input from the other hand if you want
 	local nIN_TRIGGER = IN_USE_HAND1; if (m_nHandID == 0) then nIN_TRIGGER = IN_USE_HAND0 end;
 	local nIN_GRIP = IN_GRIP_HAND1; if (m_nHandID == 0) then nIN_GRIP = IN_GRIP_HAND0 end;
 
 	-- this checks to see if the TRIGGER has been pressed on this hand
 	-- this is only set when the trigger is first pressed
 	-- if you want to see if it's HELD, check buttonsDown instead.
 	if ( input.buttonsPressed:IsBitSet( nIN_TRIGGER ) ) then
 		print( "TRIGGER is pressed" );

 		-- now clear it because we don't want any other tools to do anything with the trigger press
 		input.buttonsPressed:ClearBit( nIN_TRIGGER );
 	end
 
 	-- this checks if the TRIGGER has just been released
 	if ( input.buttonsReleased:IsBitSet( nIN_TRIGGER ) ) then
 		print( "TRIGGER is released" );

 		-- If the trigger release is not cleared, the tool will be dropped 
		-- as soon as the player releases the trigger after picking the tool up!
 		input.buttonsReleased:ClearBit( nIN_TRIGGER );
 	end
 
 	-- checks to see if the GRIP has been pressed this update
 	if ( input.buttonsReleased:IsBitSet( nIN_GRIP ) ) then
 		print( "GRIP is released" );
 		-- if it's pressed, clear the bit!
 		input.buttonsReleased:ClearBit( nIN_GRIP );
 
 		-- drop the tool
 		thisEntity:ForceDropTool();
 	end

 	-- we return the input data back to C++ code so other tools can use it
 	-- you could always return null if you want this tool to control 100% of the input...
 	return input;
 end

Parameters

Type Name Description
table input Table containing the the input state for the motion controller.


Input table

Structure of the input table passed to the function. Button values for both controllers are present in the button masks. The bit flags for the button masks can be found here.

Type Name Description
UInt64 buttonsDown Button mask for buttons being held down.
UInt64 buttonsPressed Button mask for buttons that have just been pressed.
UInt64 buttonsReleased Button mask for buttons that have just been released.
float joystickX
Todo: Find how these differ from the trackpad values.
float joystickY
float trackpadX Horizontal trackpad touch position ( -1.0 to 1.0 ).
float trackpadY Vertical trackpad touch position ( -1.0 to 1.0 ).
float triggerValue Analog trigger value ( 0 to 1.0 ).

Returns

table - Return the input table to pass the button data back to the game. Returning nil captures all button presses.