How to use "IE_Repeat" EInputEvent for Mouse Buttons

Mouse button is held as soon as it is IE_Pressed til IE_Released, there is no special type of action which marks it as held.

1 Like

Hi,
I’m trying to do bind a function for the mouse button held down, but it is not passing it through to my function. If I use a key instead, it works. I have the following:

InputComponent->BindAction(“Drag”, IE_Pressed, this, &AAbatronPlayerController::OnDragStarted);
InputComponent->BindAction(“Drag”, IE_Repeat, this, &AAbatronPlayerController::OnDragUpdate);
InputComponent->BindAction(“Drag”, IE_Released, this, &AAbatronPlayerController::OnDragReleased);

The OnDragStarted & OnDragReleased work fine with the mouse button, but the OnDragUpdate doesn’t work with mouse buttons. However, if I use a non-mouse button bind, it works?? Whats the trick to getting this to work in the C++ environment?

There has to be a way to do this sort of input handling. If the answer is to make my own input handler to monitor keystates,then I can do that. But, it seems that this is a basic function the engine should be able to do and should be easy to implement without custom handlers.

Thanks!

So, even though I would like the “IE_Repeat” EInputEvent for Mouse Buttons to work, my simple work around if anyone else wants to know is the following:

InputComponent->BindAction("Drag", IE_Pressed, this, &AAbatronPlayerController::OnDragStarted); 
//Removed this and manually call it, with custom tracking
//InputComponent->BindAction("Drag", IE_Repeat, this, &AAbatronPlayerController::OnDragUpdate);  
InputComponent->BindAction("Drag", IE_Released, this, &AAbatronPlayerController::OnDragReleased);

In the OnDragStarted(), set a member boolean true to track keydown state

In the OnDragReleased(), set the state to false

Then in your PlayerController::ProcessPlayerInput() ::

 bool bIsDragButtonDown_Old = m_bIsDragButtonDown; //track for state change for 
 Super::ProcessPlayerInput(DeltaTime, bGamePaused);

	//Key states are all updated so process any IE_Repeat for Mouse buttons,

//If there was not a state change and its true, process the “held down” function

	if (m_bIsDragButtonDown&& (bIsDragButtonDown_Old == m_bIsDragButtonDown))
	{
		OnDragUpdate();	
	}

Seems to work fine for a simple enough solution.

2 Likes

Well, there is no “held” state on hardware actually, as far as i know.
it is either pressed or released, no middle of that.

To keep track of the key being held you have to set some kind of bool to true once it’s pressed and to false once it is released.

Glad you found the solution :slight_smile:

This is a great answer and deserves more upvote.